Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What am I doing wrong? - Setting up columns

Status
Not open for further replies.

Alyxandra

Programmer
Jan 24, 2005
1
US
I'll appologize in advance, because I really don't know what I'm doing. I just started learning all of this a few days ago. The webpage I'm working with can be viewed here:
Instead of one long column, I'm trying to get this set up into two. I know how to do it, but not with the array. Here's my code:

Code:
<?php
include("connect.php");

mysql_connect($host, $user, $password);
mysql_select_db($database);

$var = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
echo "<table align=center><tr>";
echo "<td><font size=+1><b><a href=booklist.php>#</a></b></font></td>";
foreach($var as $value)
{
	echo "<td align=center><font size=+1><b><a href=\"{$_SERVER['PHP_SELF']}?list={$value}\">{$value}</a></b></font></td>";
}
echo "</tr></table><br>";

if (isset($_GET["list"]))
{
	$query = mysql_query("SELECT * FROM `books` WHERE `title` LIKE '{$_GET['list']}%' ORDER BY `title`");
}else{
	$query = mysql_query("SELECT * FROM `books` WHERE (`title` LIKE '0%') OR (`title` LIKE '1%') OR (`title` LIKE '2%') OR (`title` LIKE '3%') OR (`title` LIKE '4%') OR (`title` LIKE '5%') OR (`title` LIKE '6%') OR (`title` LIKE '7%') OR (`title` LIKE '8%') OR (`title` LIKE '9%') ORDER BY `title`");
}

while($r=mysql_fetch_array($query));
$numofrows = mysql_num_rows($result);

?>

<?php

echo "<table align=center width=700><tr><td>\n";

for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result);
    
if($i % 2) { 
echo "</TD><TD valign=top><BR><table align=center cellpadding=4 cellspacing=4>\n";
} else { 
echo "</TD></TR><TR><TD valign=top><BR><table align=center cellpadding=4 cellspacing=4>\n";
}
extract($r);
echo "<TR><td align=center bgcolor=#FFFFCE width=80><font size=-1>".$row['rarity']."</font></TD>\n";
echo "<td align=center bgcolor=#FFFFCE width=200><b>".$row['title']."</b></TD></TR>\n";
echo "<TR><td align=center bgcolor=#4A8CCE width=80>".$row['image']."</TD>\n";
echo "<td valign=center width=200><font size=-1>".$row['info']."</font></TD></TR>\n";
echo "</TABLE>\n";

}

echo "</td></tr></table>\n";

?>

I'm getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/neodaze/public_html/booklist2.php on line 29

Line 29 is this:
$numofrows = mysql_num_rows($result);

I'd greatly appreciate it if anyone can tell me what I'm doing wrong. Thanks!
 
Just a few comments that might help.

In this code segment:
Code:
while($r=mysql_fetch_array($query));
$numofrows = mysql_num_rows($result);

?>

<?php

echo "<table align=center width=700><tr><td>\n";
[ol]
[li]The while() statement is just going to loop and not do anything meaningful. It should be contructed something like:
Code:
while ($r = mysql_fetch_array($query)) {
// do something here
// and here
}
[/li]
[li]In the next statement, where does the variable "$result" come from? I don't see it in any mysql statement above it.[/li]
[li]You close the PHP segment with "?>" and then immediately reopen another with "<?php". You can delete both since there is no intervening HTML code there.[/li]
[li]You should do some error checking on you mysql_query() function.[/li]
[/ol]

There are probably more problems with your code, but I only looked at it quickly.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top