Jump to content

php loop problem


pouncer

Recommended Posts

$results = mysql_query("SELECT * FROM $cat WHERE item_id='$item_id'");
$num = mysql_num_fields($results);
$row = mysql_fetch_row($results);

$i = 0;

while ($i < $num) {
$name = mysql_field_name($results, $i);
$data = $row[$name];

echo $name . " - " . $data;
echo "<br>";

$i++;
};

 

It just echos the field names, but not the data:

 

item_id -

image_URL -

title -

media -

director -

cast -

description -

 

why is this?

Link to comment
Share on other sites

I do not know why you don't just call the array by the column name, but this should help you on your way.

 

$results = mysql_query("SELECT * FROM $cat WHERE item_id='$item_id'");

$i=0;
while ($row = mysql_fetch_array($results)) {
$num = count($row);

while ($i < $num) {
$name = mysql_field_name($results, $i);
$data = $row[$name];
echo $name . " - " . $data;
echo "<br>";
$i++;
}
}
?>

 

--FrosT

Link to comment
Share on other sites

ok thanks it prints the all now but i get error

 

Warning: mysql_field_name() [function.mysql-field-name]: Field 7 is invalid for MySQL result index 7 in

Warning: mysql_field_name() [function.mysql-field-name]: Field 7 is invalid for MySQL result index 8 in

etc.. etc.. up to index 12

 

line 214 which is

 

$name = mysql_field_name($results, $i);

 

?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.