Jump to content

Is there anythign wrong with this code?


gibigbig

Recommended Posts

$datagib = mysql_query("SELECT * FROM sotw ORDER BY id DESC") 
or die(mysql_error()); 
$infogibs = mysql_fetch_array( $datagib );
echo "<table>";
foreach ($infogibs as $infogib) {
	echo "<tr>
<td>".$infogib->id."</td>
<td>".$infogib->username."</td>
<td>".$infogib->profile_link."</td>
<td>".$infogib->category."</td>
<td>".$infogib->week."</td>
<td>".$infogib->link."</td>
<td>edit</td>
<td>delete</td>
</tr>";
}
echo "</table>";
?>

 

is the anything wrong with this, the output is :

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

edit delete

Link to comment
https://forums.phpfreaks.com/topic/198010-is-there-anythign-wrong-with-this-code/
Share on other sites

mysql_fetch_array only reads one row at a time, rather than all the rows at once

 

also the result is an array rather than an object so [ ] are used rather than ->

 

I think you mean...

 

$datagib = mysql_query("SELECT * FROM sotw ORDER BY id DESC") 
or die(mysql_error()); 
echo "<table>";
while($infogib = mysql_fetch_array( $datagib ))
{
	echo "<tr>
<td>".$infogib[id]."</td>
<td>".$infogib[username]."</td>
<td>".$infogib[profile_link]."</td>
<td>".$infogib[category]."</td>
<td>".$infogib[week]."</td>
<td>".$infogib[link]."</td>
<td>edit</td>
<td>delete</td>
</tr>";
}
echo "</table>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.