Jump to content

Recommended Posts

Hi all - new here, just stumbled upon the site in a google search for some code help.

 

Everything I've completed so far in my code development has been out of a book, so most of it should be fairly correct (I hope!).

 

A little background on my script - I run a poker league website and wanted to build a venue management back-end system to where I could easily edit/delete the venues where the league plays at, and have them dynamically displayed on each page (for each day of the week). I built all the back end and it's interfacing properly with MySQL, no glitches there... where my problem lies is in calling everything.

 

Here's the main query code and the list() function assigning all the variables...

 

$vid = "'Monday'"; //Set venue id from database
$tdid = "2"; //Set TD id from database

// Make the query.
$query = "SELECT venue_name AS name, venue_address AS address, venue_city AS city, venue_state AS state, venue_zip AS zip, venue_phone AS phone, venue_day AS venueday, venue_link AS vlink, venue_review AS vreview, venue_map1 AS vmap1, venue_map2 AS vmap2, venue_fg AS fgame, venue_sg AS sgame, venue_smoking AS vsm, venue_food AS vfd FROM venues WHERE venue_day=$vid";

$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows($result);


// Create vars to build complete venue tables

list ($name, $address, $city, $state, $zip, $phone, $venueday, $vlink, $vreview, $vmap1, $vmap2, $fgame, $sgame, $vsm, $vfd) = mysql_fetch_array($result, MYSQL_NUM);

//Create var for assigning registration start time
$vregtime = $fgame - 1;

//Pull TD info from db
$tdquery = "SELECT td_name AS tdn, td_sname AS tdsn, td_phone AS tdp, td_email AS tde FROM tds WHERE td_id=$tdid";
$tdresult = @mysql_query ($tdquery); // Run the query.

list ($tdn, $tdsn, $tdp, $tde) = mysql_fetch_array($tdresult, MYSQL_NUM);

 

Where my problem lies is on days that have more then one venue (ie. Monday - http://www.jokerspokerleague.com/venue-monday.php - the current page is all static (FYI))... the way everything is written right now, the script is only pulling the first row in the database. I've looked at syntax for using a While loop, and also thought about using an IF statement with the $num var. I've printed it to confirm it's pulling 2 rows, but am completely lost on how to print the 2nd row.

 

Here's the code for everything the vars are filling in...

 

echo '<table border="0" width="100%">
			<tr>
			<td align="left" width="*">';

		echo '<p class="venuename">' . $name . '</p>
			<strong>Address:</strong>
			<br />'
			. $address .
			'<br />'
			. $city . ', ' . $state . ' ' . $zip .
			'<br />
			Phone: ' . $phone .
			'<br />
			<br />
			Venue Review Link: <a href="' . $vreview . '" target="_blank">' . $name . '</a>
			<br />
			<br />
			<a href="' . $vlink . '" target="_blank">' . $name . ' MySpace</a>
			<br />
			<br />
			<strong>Tournament Director:</strong>
			<br />'
			. $tdn . ' - "' . $tdsn . '"
			<br />
			Phone: ' . $tdp . 
			'<br />
			<a href="mailto:' . $tde . '">Email ' . $tdn . '!</a>
			<br />
			<p class="darkredbold">
			Early registration: ' . $vregtime . 'pm-' . $vregtime . ':30pm
			<br />
			1st game: ' . $fgame .
			'<br />
			2nd game: ' . $sgame .
			'</p>';

			// Build smoking images.
		if ($vsm == "Smoking") {
			echo '<img src="http://www.jokerspokerleague.com/images/smoking.jpg" alt="Smoking" title="Smoking" width="50" height="50 />';
		} elseif ($vsm == "Non Smoking") {
			echo '<img src="http://www.jokerspokerleague.com/images/nosmoking.jpg" alt="Non Smoking" title="Non Smoking" width="50" height="50" />';
		} else {
			echo ' ';
		}

	// Build food images
		if ($vfd == "Bar Food") {
			echo '<img src="http://www.jokerspokerleague.com/images/barfood.jpg" alt="Bar Food" title="Bar Food" width="50" height="50" />';
		} elseif ($vfd == "Full Menu") {
			echo '<img src="http://www.jokerspokerleague.com/images/fullmenu.jpg" alt="Full Menu" title="Full Menu" width="50" height="50" />';
		} else {
			echo ' ';
		}

			echo '</td>
			<td align="right" valign="top" width="205">
			<iframe style="margin-top:45px;" width="200" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' . $vmap1 . '"></iframe><br /><small><a href="' . $vmap2 . '" style="color:text-align:left;" target="_blank">View Larger Map</a></small>
			</td>
			</tr>
			</table>
			<!-- end inner table -->
				</td>
			    </tr>
			    </table>
			    <!-- end outter table -->';

 

Thank you all in advance. It seems from reading and searching around here that there are some VERY knowledgeable people here! Look forward to knowing what I'm doing wrong.... :facewall:

Link to comment
https://forums.phpfreaks.com/topic/170453-while-loop-or-if-statement/
Share on other sites

This

list ($name, $address, $city, $state, $zip, $phone, $venueday, $vlink, $vreview, $vmap1, $vmap2, $fgame, $sgame, $vsm, $vfd) = mysql_fetch_array($result, MYSQL_NUM);

 

should be

if(mysql_num_rows($result) > 0)
{
    while(list ($name, $address, $city, $state, $zip, $phone, $venueday, $vlink, $vreview, $vmap1, $vmap2, $fgame, $sgame, $vsm, $vfd) = mysql_fetch_row($result))
    {
        // your code here for displaying the row
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.