timmah1 Posted December 27, 2008 Share Posted December 27, 2008 I have this section that will show information based on the sport they bought. It works fine if there is only one sport, but when there is more than one, it only shows the last one. How can I show all sports that are in the database as well as it's information? Here is my code. Like I said, as long as there is only one sport, it works great, I just need to make it show every sport <?php session_start(); if(isset($_SESSION['SESS_LOGGEDIN']) == FALSE){ header("Location: " . $config_basedir . "/login.php?error=1"); } require("header.php"); ?> <table width="95%" border="0" align="center" cellpadding="6" cellspacing="0"> <tr> <td><?php $today = date("Y-m-d h:i a"); $today1 = date("Y-m-d"); $id = $_SESSION['SESS_EMAIL']; $pass = $_SESSION['SESS_PASS']; //Select user from Member Database $sql20 = "SELECT * FROM members WHERE email = '$_SESSION[sESS_EMAIL]' ORDER BY id ASC LIMIT 1"; $q20 = mysql_query($sql20); while($a20 = mysql_fetch_assoc($q20)){ if($a20[first] == ""){ echo "Welcome Back $a20[email]<br />"; } else { echo "Welcome Back $a20[first] $a20[last]<br />"; echo "<a href='logout.php'>Logout</a><br /><br />"; } } //End member database selection //grab members information from the sales database $sql = "SELECT DISTINCT sport, package, exp, user FROM memPack WHERE user = '$id' AND password = '$pass'"; $q = mysql_query($sql); while($a = mysql_fetch_assoc($q)){ $format = date("Y-m-d h:i a", strtotime($a['exp'])); //if their key is expired, tell them if($a['exp'] < $today) { echo "Your access key has expired.<br> Please click below to purchase another lock or special offer.<br>"; echo "<a href='https://secure.vegasdsports.com'>Order Another Package here</a>"; } else { //Select sport and package name from the sports selected echo "<h1>$a[package]</h1>"; echo "Your key expiration date is: $format<p></p><br><br>"; $sql11 = "SELECT * FROM $a[sport]"; $q11 = mysql_query($sql11); while($a11 = mysql_fetch_assoc($q11)){ if($a11['name'] == $a['package']){ if($a11['id'] == "1"){ $pick = "sngl"; } if($a11['id'] == "2"){ $pick = "ult"; } if($a11['id'] == "3"){ $pick = "mnth"; } if($a11['id'] == "4"){ $pick = "ssn"; } if($a11['id'] == "5"){ $pick = "po"; } if($a11['id'] == "6"){ $pick = "spl"; } $sql12 = "SELECT * FROM dailypicks1 WHERE package = '$pick' AND sport = '$a[sport]' AND active = '$today1'"; $q12 = mysql_query($sql12); $numrows = mysql_num_rows($q12); if($numrows < 0){ echo "Thank you for your purchase<br /> You are now authorized for today's selections.<br />Today's picks have not been posted at this time.<br />Please check back later for our picks.<br><br>"; } while($a12 = mysql_fetch_assoc($q12)){ $expTime = "$today1 $a12[time_spl]"; $today2 = date("Y-m-d H:i:s", strtotime($expTime)); $today3 = date("Y-m-d H:i:s"); $today4 = date("Y-m-d 00:00:00"); if($a12['time_spl'] == "00:00:00") { echo "<span class='picks'>".nl2br($a12['picks'])."</span>"; } elseif($today2 <= $today3){ echo "Your Special access key has expired.<br> Please click below to purchase another special offer.<br>"; echo "<a href='https://secure.vegasdsports.com'>Order Another special Package here</a>"; } } } //end package } //end package selection } //end selecting sales database } ?></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table> <?php require("footer.php"); ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/138570-solved-only-showing-one-sport-when-it-should-show-2/ Share on other sites More sharing options...
timmah1 Posted December 27, 2008 Author Share Posted December 27, 2008 ok, I think I know what needs to be done, I'm just not sure how to do it. If there is more than one sport for this particular user, how do I loop this query? If there is 1, run once, if there are 3, loop three times and so forth This is the code that needs to loop echo "<h1>$a[package]</h1>"; echo "Your key expiration date is: $format<p></p><br><br>"; $sql11 = "SELECT * FROM $sport"; $q11 = mysql_query($sql11); while($a11 = mysql_fetch_assoc($q11)){ if($a11['name'] == $a['package']){ if($a11['id'] == "1"){ $pick = "sngl"; } if($a11['id'] == "2"){ $pick = "ult"; } if($a11['id'] == "3"){ $pick = "mnth"; } if($a11['id'] == "4"){ $pick = "ssn"; } if($a11['id'] == "5"){ $pick = "po"; } if($a11['id'] == "6"){ $pick = "spl"; } $sql12 = "SELECT * FROM dailypicks1 WHERE package = '$pick' AND sport = '$sport' AND active = '$today1'"; $q12 = mysql_query($sql12); $numrows = mysql_num_rows($q12); if($numrows < 0){ echo "Thank you for your purchase<br /> You are now authorized for today's selections.<br />Today's picks have not been posted at this time.<br />Please check back later for our picks.<br><br>"; } while($a12 = mysql_fetch_assoc($q12)){ $expTime = "$today1 $a12[time_spl]"; $today2 = date("Y-m-d H:i:s", strtotime($expTime)); $today3 = date("Y-m-d H:i:s"); $today4 = date("Y-m-d 00:00:00"); if($a12['time_spl'] == "00:00:00") { echo "<span class='picks'>".nl2br($a12['picks'])."</span>"; } elseif($today2 <= $today3){ echo "Your Special access key has expired.<br> Please click below to purchase another special offer.<br>"; echo "<a href='https://secure.vegasdsports.com'>Order Another special Package here</a>"; } } } } I'm tried this for( $i = 0; $i < count($sport); $i++ ) { } But that just does the same thing it does now. Thanks again Link to comment https://forums.phpfreaks.com/topic/138570-solved-only-showing-one-sport-when-it-should-show-2/#findComment-724536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.