php & sql problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

php & sql problem?

Post by itsmani1 »

Hello Every One.

i have a table and 2 columns in it what i want's to do is that fetch the info that is in both columns one column name is 'title' and other's name is 'info' against each title it contains some info and i just know the name of 2 coumns . Now i had to fetch all the titles from table along with the coross-ponding info.

Code: Select all

<?php
$res = mysql_query($query) or die(mysql_error);
$norow = mysql_num_rows($res);
?>
using the above code i can get the #of effected records but how can i fetch all the record from the column.
i mean how can i will be able to featch all the titles. ?

Regards :-
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

The mysql_fetch_assoc() function fetches an associative array. If you want only that, use that function, if you want indices, use the mysql_fetch_row() function. If for some reason you need both, then you should use the mysql_fetch_array() function; do not assign what you will not use.

Code: Select all

<?php
    $res = mysql_query($query) or die(mysql_error());
    $norow = mysql_num_rows($res) or die(mysql_error());
    if($norow > 0) &#123;
        while($row = mysql_fetch_assoc($res)) &#123;
            extract($row);
            echo $title . '<br>' . $info;
        &#125;
    &#125;
?>
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

thanks

Post by itsmani1 »

Many and Many thanks Kriek

U made the job easy
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

No problem, glad I could be of assistance to you.
Post Reply