Jump to content

Archived

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

chriscloyd

Mysql_fretch_array

Recommended Posts

i get this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.giro/thegtz/aspire-hosting.net/includes/latestthreads.php on line 5

and my code is

[code]<?php
include("threaddb.php");
$latest = mysql_query("SELECT * FROM 'thread' ORDER BY date DESC 'threadid' LIMIT '7'");
echo '<table width="193" border="0" bordercolor="#000000" bgcolor="#FFFFFF">';
while ($row = mysql_fetch_array ($latest)){
echo '<tr>
    <td width="105"><div align="left">'.$row['title'].'</div></td>
    <td width="78"><div align="center"><a href="forums/showthread.php?t'.$row['threadid'].'">View</a></div></td>
  </tr>';
}
echo '</table>';
?>[/code]

can someone help me fast please

Share this post


Link to post
Share on other sites
Try:

[code]
<?php
include("threaddb.php");
$latest = mysql_query("SELECT * FROM 'thread' ORDER BY date DESC 'threadid' LIMIT '7'");
while ($row = mysql_fetch_array ($latest)){
$title = $row['title'];
$threadid = $row['threadid'];
?>
<table width="193" border="0" bordercolor="#000000" bgcolor="#FFFFFF">';
<tr>
<td width="105"><div align="left"><?php echo $title; ?></div></td>
<td width="78"><div align="center"><a href="forums/showthread.php?t=<?php echo $threadid; ?>'">View</a></div></td>
</tr>
<?php
}
echo '</table>';
?>
[/code]

Share this post


Link to post
Share on other sites
Not sure if it matters, but try:

[code]
<?php
include("threaddb.php");
$latest = mysql_query("SELECT * FROM 'thread' ORDER BY date DESC 'threadid' LIMIT '7'");
while ($row = mysql_fetch_array($latest)){ //took out the space
$title = $row['title'];
$threadid = $row['threadid'];
?>
<table width="193" border="0" bordercolor="#000000" bgcolor="#FFFFFF">';
<tr>
<td width="105"><div align="left"><?php echo $title; ?></div></td>
<td width="78"><div align="center"><a href="forums/showthread.php?t=<?php echo $threadid; ?>'">View</a></div></td>
</tr>
<?php
}
echo '</table>';
?>
[/code]

Share this post


Link to post
Share on other sites
It's different than the first one I posted, I commented on the slight difference. I said I wasn't sure if it mattered, but the first one was:

[code]
while ($row = mysql_fetch_array ($latest)){
[/code]

The second one was:

[code]
while ($row = mysql_fetch_array($latest)){ //took out the space
[/code]

Share this post


Link to post
Share on other sites
ya i did and it still doesnt lol
any other way of doing what im trying to do im trying to get the 7 newest rows by id from threads

Share this post


Link to post
Share on other sites
Are you sure "thread" is a table in the database? And that date, threadid, and title are all fields in the table "thread" ?

Share this post


Link to post
Share on other sites
ya the error im getting now is

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'threadid LIMIT 7' at line 1

and my mysql_query is

mysql_query("SELECT * FROM thread ORDER BY threadid DESC threadid LIMIT 7") or die(mysql_error());

Share this post


Link to post
Share on other sites
I think the problem might be:

[code]
$latest = mysql_query("SELECT * FROM 'thread' ORDER BY date DESC 'threadid' LIMIT '7'");
[/code]

Try changing that to:

[code]
$latest = mysql_query("SELECT * FROM 'thread' ORDER BY date, threadid DESC LIMIT 0, 7");
[/code]

Share this post


Link to post
Share on other sites
Why was the threadid in there anyways? Were you trying to order the page by the threadid as well?

Share this post


Link to post
Share on other sites
ya but i already had it b4 desc thats why.  but now its messing up my whole page [url=http://www.aspire-hosting.net]www.aspire-hosting.net[/url]

Share this post


Link to post
Share on other sites
Most likely you moved the "}" to where after the rows were selected? It won't work then because it cannot loop through all the results.

Share this post


Link to post
Share on other sites
[code]<?php
include("threaddb.php");
$latest = mysql_query("SELECT * FROM thread ORDER BY threadid DESC LIMIT 7") or die(mysql_error());
echo '<table width="193" border="0" bordercolor="#000000" bgcolor="#FFFFFF">';
while ($row = mysql_fetch_array($latest)){

$title = $row['title'];
$threadid = $row['threadid'];
echo '<tr>
<td width="105"><div align="left">'.$title.'</div></td>
<td width="78"><div align="center"><a href="forums/showthread.php?t'.$threadid.'">View</a></div></td>
</tr>';
}
echo '</table>';
?>[/code]

Share this post


Link to post
Share on other sites
look on the normal page

http://www.aspire-hosting.net/includes/latestthreads.php
it shows it but when u go to
http://www.aspire-hosting.net
it wont

Share this post


Link to post
Share on other sites
i just dont know why it will work when u go to the actuall page like
http://www.aspire-hosting.net/includes/latestthreads.php
but not when u go to
http://www.aspire-hosting.net

I have tried where i just post the code on the index.php file but it still wont show!

Share this post


Link to post
Share on other sites

×

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.