Page 1 of 1

php & sql problem?

Posted: Wed Oct 22, 2003 12:57 am
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 :-

Posted: Wed Oct 22, 2003 1:34 am
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;
?>

thanks

Posted: Wed Oct 22, 2003 2:03 am
by itsmani1
Many and Many thanks Kriek

U made the job easy

Posted: Wed Oct 22, 2003 8:32 am
by Kriek
No problem, glad I could be of assistance to you.