SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Using the SELECT * Command
-
Oct 16, 2009, 11:09 #1
- Join Date
- Oct 2009
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using the SELECT * Command
Hello,
I have the following code listed below, but it is only displaying one entry. Hoping you can help!
<?php
// Select WSR Database
mysql_select_db("wsrskitites");
// Retrieve all the data from the skisites table
$result = mysql_query("SELECT * FROM skisites")
or die(mysql_error());
echo "<table border='1' width='650' cellpadding='0' cellspacing='0'>
<tr bgcolor='#333333'>
<th valign='top'><p align='center' class='title'><b>State</b></p></th>
<th valign='top'><p align='center' class='title'><b>City</b></p></th>
<th valign='top'><p align='center' class='title'><b>Ski Site</b></th>
<th valign='top'><p align='center' class='title'><b>Website Address</b></p></th>
<th valign='top'><p align='center' class='title'><b>Contact Info</b></p></th>
</tr>";
// store the record of the skisites table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
{
echo "<tr>";
echo "<td>".$row['State'] ."</td>";
echo "<td>".$row['City'] ."</td>";
echo "<td>".$row['Site_Name'] ."</td>";
echo "<td>".$row['Website'] ."</td>";
echo "<td>".$row['Contact'] ."</td>";
echo "</tr>";
}
echo "<br>";
echo "</table>";
?>
-
Oct 16, 2009, 12:33 #2
- Join Date
- May 2007
- Location
- Poole, UK
- Posts
- 5,077
- Mentioned
- 103 Post(s)
- Tagged
- 0 Thread(s)
You need to loop through until there are no more matches left using a while loop:
PHP Code:while ($row = mysql_fetch_array( $result )) {
<code to display results>
}
Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
-
Oct 16, 2009, 13:39 #3
- Join Date
- Oct 2009
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks so much for answering my question! I don't know how many more you are interested in but I will post a couple of other challenges:
1. I want to take my list and divide them out by state but I want it to have a format like this:
5 Columns and the title of the column put in when a new set of listings starts for a state by state basis. Someone told me that I could type one line of code and it's possible but I'm not sure. If not, I do know how to break it out with WHERE state=""
2. I have a column for email addresses and one for website addresses, and instead of displaying someonesname@somedomain.com , I want to put "EMAIL" or something in it's place. I'll do the same for a website listing and link them up but not all entries have a website or email address so I don't want a link created if there is no address behind them.
Thanks again for your time! It's greatly appreciated.
-
Oct 17, 2009, 16:37 #4
- Join Date
- May 2007
- Location
- Poole, UK
- Posts
- 5,077
- Mentioned
- 103 Post(s)
- Tagged
- 0 Thread(s)
- You would need to use an 'ORDER BY' clause to group the records in order of the state. I'm not sure if you can add the column headings after each group of records for a state, with the 'ORDER BY' clause, you might well need to loop through an array of states (in the order that you want them in), where each time the column names are printed and the records for that state are then printed with the state name that the loop as reached from the array being passed to the query for the 'WHERE' clause.
- For the email address, i think your looking at in the loop that displays the records, where it comes to the display of the email address something like:PHP Code:
if ($email == null) {
echo 'No E-mail Address';
} else {
echo "<a href='$mail'>e-mail</a>";
}
Hope that helps.Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
-
Nov 1, 2009, 17:28 #5
- Join Date
- Oct 2009
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks again for your feedback. I have been busy and haven't had a chance to try this yet, but I will and let you know what worked. Thanks!
-
Nov 15, 2009, 01:40 #6
- Join Date
- Oct 2009
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you for your help and and I want to post the code, but this forum won't let me post a link and that is included in my code
Bookmarks