Click to See Complete Forum and Search --> : help pyro or someone ;)


lukezweb
12-17-2003, 12:25 PM
please help, i get this error.....


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/shoutbox/public_html/lukezwebforum/forum.php on line 263



############################
# GENERAL BOARD ###############
############################


} else if ($action == "general") {
?>
<center>
<form name='general' method='post'>
<table width='95%' cellspacing='2' bgcolor='black' cellpadding='1' border='0'>
<tr><td class='catbg'>
<table width='100%'>
<tr><td width='50%'>
<div align='left'>Welcome, Guest!</div>
</td>
<td width='50%'>
<div align='right'>
<?php print date("G:i:sa , j/m/Y"); ?>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class='windowbg'>
<center>
Lukezweb Forum - <a href='forum.php?action=main'>Home</a> - <a href='forum.php?action=portal'>Portal</a> - <a href=forum.php?action=help'>Help</a>
</center>
</td>
</tr>
<tr>
<td class='windowbg'>General Board</td>
</tr>
<tr><td class='windowbg'><table width='100%' border='0' cellspacing='1' bgcolor='#000000'><tr>
<td colspan='2' class='windowbg2' height='20' align='center' valign='middle'>Topics</td>
<td width='10%' class='windowbg2' align='center' valign='middle' height='20'>Started By</td>
<td width='10%' class='windowbg2' align='center' valign='middle' height='20'>Replies</td>
</tr>
<tr>
<td class='windowbg' colspan='4'>Stickies:</td>
</tr>
<tr>
<td width='10%' class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';"><img src=http://geocities.com/lukezwebforum11/new.txt></td>
<td class=windowbg onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';"><a href=forum.php?action=post000>Welcome, First Working Thread!</a></td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';">Luke</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';">0</td>
</tr>
</tr>
<tr>
<td class='windowbg' colspan='4'>Topics:</td>
</tr>
<?php
$dbh=mysql_connect ("localhost", "shoutbox_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("shoutbox_forum");
$querytop = "SELECT `id` , `threadname` , `psotedby` FROM `generaltalk` WHERE 1 AND `id` > 0 ORDER BY `id` DESC LIMIT 0 , 20 ";
$topics = mysql_query($querytop) or die ("Couldn't execute query.");
while ($topics = mysql_fetch_array($topics)) {
$topics = str_replace("\n", "<br>", $topics);
$topics = str_replace("<", "<!--", $topics);
$topics = str_replace(">", "-->", $topics);
$topics = str_replace("\'", "'", $topics);
echo "<tr>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
<img src='http://geocities.com/lukezwebforum11/new.txt'>
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
".$row['threadname']."
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
".$row['psotedby']."
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
0
</td>
</tr>";
}
?>
</table>
</td>
</tr>
</table>
</center>
</form>
<?php

pyro
12-17-2003, 12:33 PM
Two things that jump out at me.

One is the SQL statement. What is it that you are trying to do? Why did you use WHERE 1 AND `id` > 0.

And the second is the while loop. I would not reuse the variable as you have done, or it will only loop through once.

lukezweb
12-17-2003, 12:34 PM
Originally posted by pyro
Two things that jump out at me.

One is the SQL statement. What is it that you are trying to do? Why did you use WHERE 1 AND `id` > 0.

And the second is the while loop. I would not reuse the variable as you have done, or it will only loop through once.


so what should it be?

pyro
12-17-2003, 12:36 PM
What are you trying to select?

For the while loop, just use two different variables.

lukezweb
12-17-2003, 12:38 PM
Originally posted by pyro
What are you trying to select?

For the while loop, just use two different variables.

im trying to do......

SELECT `id` , `threadname` , `psotedby`
FROM `generaltalk`
ORDER BY `id` DESC
LIMIT 0 , 20

and then a way to display them......



while ($topics = mysql_fetch_array($topics)) {
$topics = str_replace("\n", "<br>", $topics);
$topics = str_replace("<", "<!--", $topics);
$topics = str_replace(">", "-->", $topics);
$topics = str_replace("'", "'", $topics);
echo "<tr>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
<img src='http://geocities.com/lukezwebforum11/new.txt'>
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
".$row['threadname']."
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
".$row['psotedby']."
</td>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
0
</td>
</tr>";
}




in that table format but for all values in the table ?
thanks :)

pyro
12-17-2003, 01:05 PM
Try running that query instead of the one you had and see if it works better.

lukezweb
12-17-2003, 01:24 PM
Originally posted by pyro
Try running that query instead of the one you had and see if it works better.



the one i just posted i had copied and pasted form above? can u show me what u mean?

pyro
12-17-2003, 01:28 PM
They don't look the same to me:

Originally posted by lukezweb

$querytop = "SELECT `id` , `threadname` , `psotedby` FROM `generaltalk` WHERE 1 AND `id` > 0 ORDER BY `id` DESC LIMIT 0 , 20 ";

Originally posted by lukezweb
SELECT `id` , `threadname` , `psotedby`
FROM `generaltalk`
ORDER BY `id` DESC
LIMIT 0 , 20

lukezweb
12-17-2003, 01:38 PM
Originally posted by pyro
They don't look the same to me:


oh ok ?


so whats the code then? :confused:


sorry am confused :S

pyro
12-17-2003, 04:48 PM
Try:

$querytop = "SELECT `id`, `threadname`, `psotedby` FROM `generaltalk` ORDER BY `id` DESC LIMIT 0, 20";

And don't forget to change the name of the variable in your while loop.

lukezweb
12-18-2003, 10:00 AM
Originally posted by pyro
Try:

$querytop = "SELECT `id`, `threadname`, `psotedby` FROM `generaltalk` ORDER BY `id` DESC LIMIT 0, 20";

And don't forget to change the name of the variable in your while loop.


ok i got this to work :)

i have another questions how can you get the number of rows in and sql table ?

so in a table containing posts by one board, you can say on the boards index page, how many posts (rows) are on that board :)

pyro
12-18-2003, 10:09 AM
mysql_num_rows() (http://us4.php.net/manual/en/function.mysql-num-rows.php) ;)

lukezweb
12-18-2003, 10:22 AM
Originally posted by pyro
mysql_num_rows() (http://us4.php.net/manual/en/function.mysql-num-rows.php) ;)


ah thanks but i get this.....

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/shoutbox/public_html/lukezwebforum/forum.php on line 215

pyro
12-18-2003, 10:28 AM
How are you trying to use it?

lukezweb
12-18-2003, 10:34 AM
Originally posted by pyro
How are you trying to use it?


u want to se the full code?

pyro
12-18-2003, 10:36 AM
No, just the bit that would show me how you use mysal_num_rows, please.

lukezweb
12-18-2003, 10:38 AM
Originally posted by pyro
No, just the bit that would show me how you use mysal_num_rows, please.


ok.......


############################
# GENERAL BOARD ###############
############################


} else if ($action == "general") {
$link = mysql_connect("localhost", "shoutbox_admin", "admin");
mysql_select_db("shoutbox_forum", $link);
$result = mysql_query("SELECT * FROM posts001", $link);
$num_rows = mysql_num_rows($result);
?>
<center>
<form name='general' method='post'>
<table width='95%' cellspacing='2' bgcolor='black' cellpadding='1' border='0'>
<tr><td class='catbg'>
<table width='100%'>
<tr><td width='50%'>
<div align='left'>Welcome, Guest!</div>
</td>
<td width='50%'>
<div align='right'>
<?php print date("G:i:sa , j/m/Y"); ?>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class='windowbg'>
<center>
Lukezweb Forum - <a href='forum.php?action=main'>Home</a> - <a href='forum.php?action=portal'>Portal</a> - <a href=forum.php?action=help'>Help</a>
</center>
</td>
</tr>
<tr>
<td class='windowbg'>General Board</td>
</tr>
<tr><td class='windowbg'><table width='100%' border='0' cellspacing='1' bgcolor='#000000'>
<tr>
<td colspan='2' class='windowbg2' height='20' align='center' valign='middle'>
Topics
</td>
<td class='windowbg2' align='center' valign='middle' height='20'>
Started By
</td>
<td class='windowbg2' align='center' valign='middle' height='20'>
Replies
</td>
</tr>
<tr>
<td class='windowbg' colspan='4'>Stickies:</td>
</tr>
<tr>
<td class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';"><img src=white.gif></td>
<td class=windowbg onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';"><a href=forum.php?action=post000>Welcome, First Working Thread!</a></td>
<td class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';">Luke</td>
<td class='windowbg' align='center' valign='middle' height='20' onMouseOver="this.style.backgroundColor = '444444'; style.cursor='hand'" onMouseOut="this.style.backgroundColor ='';">0</td>
</tr>
</tr>
<tr>
<td class='windowbg' colspan='4'>Topics:</td>
</tr>
<?php

$query = "SELECT `id` , `threadname` , `psotedby` FROM `generaltalk` WHERE 1 AND `id` > 0 ORDER BY `id` LIMIT 0 , 20 ";
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
$row = str_replace("\n", "<br>", $row);
$row = str_replace("<", "<!--", $row);
$row = str_replace(">", "-->", $row);
$row = str_replace("\'", "'", $row);
echo "<tr>
<td width='10%' class='windowbg' align='center' valign='middle' height='20'>
<img src=white.gif>
</td>
<td width='50%' class='windowbg' align='center' valign='middle' height='20'>
".$row['threadname']."
</td>
<td width='20%' class='windowbg' align='center' valign='middle' height='20'>
".$row['psotedby']."
</td>
<td width='20%' class='windowbg' align='center' valign='middle' height='20'>
$num_rows
</td>
</tr>";
}
?>
</table>
</td>
</tr>
</table>
</center>
</form>
<?php

pyro
12-18-2003, 11:04 AM
is posts001 the name of your table?

lukezweb
12-19-2003, 04:11 AM
Originally posted by pyro
is posts001 the name of your table?


yes :)

pyro
12-19-2003, 07:11 AM
Hmm... everything looks right. That's why I asked if posts001 was your table - it sounded more like an entry ID or something, which would cause it not to work.