PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('tomsace_games') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM games';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
echo "$col_value";
}
}
// Closing connection
mysql_close($link);
?>
This shows all data in the table, how do I show onbe specific piece of data? for example at the minuthe this shows a games title, description, instrucations and date added to the site, how do I show just the title?
Now all my games in my database are listed in categories (action, adventure, fighting etc...)
How do I show all games that are listed under 'action' under the 'category' part of my database?
Thanks alot.
One last thing is I was wondering if it is possible to use these 'titles' I am using from my database as an image?
I need to use each title as an image.
For example: <img src="images/TITLE FROM DATABASE.jpg" height="75" width="75">...
This is my code to use the data stored in mysql database. How do I filter these results to show only games that under the 'category' section say 'action' etc..
Earlier Tasairis said
You change your query so it only SELECTs the rows WHERE the category is "action".
My results are returned in a column and just span across the whole page.
How do I edit my results so that after showing about 7 results, a <br> to go down a page?
Can this be done using the 'limit' code by setting it to 7 and start listing again on the next line?
// Performing SQL query
$query = 'SELECT * FROM games ORDER BY id DESC';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
TEXT
}
Before I add this code the table looks like it should except my images and text from the database isn't showing. When I add the code above all the images and text from the database show but...
Well visit http://www.zippygame.com/categories.php?id=all and see...
Any help or advice on how I can add my code to the script but keep it working?
That example was not meant to be "plug and play". It was a demonstration of how to cause a row break between cells at a regular interval. The for loop in the example represents the while loop in your script.
You are burying yourself in tables. Have you considered first building the page manually to see how the HTML code should look, then adding the PHP when the layout design is complete?
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 1:40 pm, edited 1 time in total.