I have just created a small site using PHP and MySQL. It was basicly a conversion from using a PHP datafile to using a MySQL database as it's back-end...
I have two tables (so far):
"infodivs"
id|teamname|displayname|content
0 |test |The Test |A sentence
1 |test2 |The Test2 |.......
2 |test3 |The Test3 |......
3 |etc... |Et Cetera |.......
and "content"
id|teamname|content
0|test |Some HTML code
1|test2 |...
2|test3 |.......
3|ect. |............
I am using the "infodivs" table to create a menu. (it may be useful to see here). This menu will contain a link (in a <li>) to ?team=[teamname field] with the text being [displayname]. I also need the link to have a "onmouseover" set as
toggleDiv('[teamname]',1)
and a onmouseout as
toggleDiv('[teamname]',0)
I then ALSO, a little after that, (to make valid XHTML) put the "content" field in a div with the class "info" and the id [teamname]. (this is so they can appear on mouseover)
This is my current code:
<?php // LINE 86
// Copyright (C) 2006 ThePeccavi/Isaac Seymour
// If no team is specified, go to home
if(!isset($team)){
$team = 'home';
}
// Else, just strtolower()
else{
$team = strtolower($team);
}
// Connect to db
$mysqlConnect = mysql_connect(localhost, root);
// Prepare query
$getMenu ='SELECT * FROM infodivs ORDER BY displayname ASC';
// Run query
$getMenuResults = mysql_query($getMenu);
// Process results:
// Create div, list, "Home" link and "The Teams:" header
echo '<div id="teamslist">
<ul>
<li><a href="/">Home</a></li>
<h2>The Teams:</h2>
';
// Print List items
while($item = mysql_fetch_assoc($getMenuResults)){ // LINE 115
printf(" <li><a href=\"?team=%s\" onmouseover=\"toggleDiv('%s',1)\" onmouseout=\"toggleDiv('%s',0)\">%s</a></li>", $item['teamname'], $item['teamname'], $item['teamname'], $item['displayname']);
}
// Close list and div
echo '</ul>' . "\n\n\n";
// Create info divs
while($div = mysql_fetch_assoc($getMenuResults)){ // LINE 121
printf("<div class=\"info\" id=\"%s\"><p>%s</p></div>", $div['teamname'], $div['content']);
}
echo '$getMenuResults: ' . $getMenuResults;
?>
These are my errors:
For making the list:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\bscdb\index.php on line 115
for making the divs (class="info")
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\bscdb\index.php on line 121
NOTE: you probably noticed that I have tried printing the "$getMenuResults" variable... NOTHING is returned, it is a blank variable.
======================================================
And THAT is JUST THE BEGINNING!!!
I now want to use the content table. This is MUCH simpler (I think 😉 )
All I want to do is query the info (using the "teamname" field to find the right one) and print it into a div! Still... I am getting this error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\bscdb\index.php on line 139
This is my code:
<div id="text">
<?php // LINE 131
// Create query for content
$getContent = 'SELECT \'content\' FROM \'content\' WHERE user = \'' . $team . '\'';
// Run query
$getContentResults = mysql_query($getContent);
// Process that stuff
while($content = mysql_fetch_assoc($getContentResults)){ // LINE 139
printf("%s", $content['content']);
}
?>
<div class="shade"></div>
</div>
Thank you for your help