I'm trying to get two separate mysql cells to be echoed on a single page. The first cell is working with no problems, but I haven't managed a way to get the second one to work.
Code:
<?php
//Connect to server and database
include'config.php';
mysql_connect("$host", "$username", "$password") or die(mysql_error());
//echo "Connected to your mysql<br/>";
mysql_select_db("$db_name") or die(mysql_error());
//echo "Connected to database<br/>";
$result=mysql_query("SELECT * FROM books WHERE Genre LIKE '%Fiction%' ORDER BY title ASC");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<div>
<?php include("menu.php"); ?>
</div>
<div id="Items">
<br /> <br />
<?php
while($row=mysql_fetch_array($result))
{
echo "".$row['Information']."";
}
?>
</div>
<div id="mystickytooltip" class="stickytooltip">
<div style="padding:5px">
<?php
while($row=mysql_fetch_array($result))
{
echo "".$row['Tooltip']."";
}
?>
</div>
</div>
</body>
</html>
On both your mysql_connect and mysql_select_db functions you have "or die(mysql_error()). If something goes wrong. this little bit of code is going to let you know. If you don't see any messages then you can just assume your connection is successful.
Also I don't recommend ever using "SELECT *" in your queries unless you really need to select every single column in a table because it's a waste of CPU cycles and probably RAM too. The more your site wastes computer "power," if you will, the less people your site will be able to handle on it at one time. The alternative to "SELECT *" is listing the columns you want e.g. on an employee table I might do "SELECT `employee_name`, `employee_id`, `department_id`"
Anyway, I'm not entirely sure if my advice about this next part is the best advice, but what I would have personally done is an entirely separate query for "Tooltip". If someone has a better idea, they'll probably come along and correct me. I am an intermediate PHP programmer so and they're, like, pros, so yeah.
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
One reason I can see that might be your problem is that you're iterating through the same resultset twice, the second time obviously starting at the end of the recordset and immediately returning false.
You could either try and extract both fields of information at the same time and store it in an array for further processing, or rewind the recordset using mysql_data_seek:
Bookmarks