doc4414 Posted November 26, 2011 Share Posted November 26, 2011 Having problem with a bit of code. I am trying to fetch data from the database, I have used mysql_fetch_array before, and even in later bits of code. I want to use this data for an IF statement later on. The IF statement isn't there, because this code is catching somewhere. The fetch array is working fine, and it echos out the correct row in database that it should. The issue, it stops displaying code that follows it. In the code, I have put a comment (// Code kills here ....) where the code is killing. I have identified the few lines of code that is killing the script. You can see the page.. The number 71 is what is supposed to be supplied by the query and array. This is the page as it is with the trouble code. Here is the page without the trouble bit of code, and it displays all that it should. But it doesn't have the functionality I want to build in with the array obviously. Here is the code with highlight bit of trouble: /source/userinfo.php <?php include ("db.php"); $get_info = mysql_query ("SELECT * FROM registrations WHERE u_id=$uid AND appid=$appid" , $link2); //Begin Trouble Code while ($check = mysql_fetch_array($get_info)) { echo $check['assign_id']; } //End Trouble Code // Code kills here, for some reason.... Proper assign_id displayed, but it kills script. $count = mysql_num_rows($get_info); if ($count >= 1) { $get_jos_info = mysql_query ("SELECT * FROM jos_users WHERE id=$appid" , $link); $get_avatar = mysql_query ("SELECT * FROM jos_comprofiler WHERE user_id=$appid" , $link); while ($avatar_link = mysql_fetch_array($get_avatar)) $avatarurl = $avatar_link['avatar']; echo $avatar_link['avatar']; echo "<table border='0' width='70%' align='center' cellpadding=5>"; while ($rowteam = mysql_fetch_array($get_info)) { while ($rowjos = mysql_fetch_array($get_jos_info)) { $urlbegin = "<img src='http://versionxlegends.com/images/comprofiler/tn"; $urlend = "'>"; echo "<tr><td width=100% align=center colspan=2>".$urlbegin.$avatarurl.$urlend."</td></tr>"; echo $avatar; echo "<tr><td width=40% align=right><strong>Registration #</strong></td><td width=60% align=center>$rowjos[id]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Username</strong></td><td width=60% align=center>$rowteam[username]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Name</strong></td><td width=60% align=center>$rowteam[name]</td></tr>"; echo "<tr><td width=40% align=right><strong>Provided Skype Username</strong></td><td width=60% align=center>$rowteam[skype]</td></tr>"; //Add script for lead only view Email Address. Team Member, field is hidden. Lead sees email and a YES/NO if email matches. If not, lead will email user to get email verification, to edit account before assignments occur. echo "<tr><td width=40% align=right><strong>E-Mail Address</strong></td><td width=60% align=center>$rowteam[email]</td></tr>"; echo "<tr><td width=40% align=right><strong>Registration Date</strong></td><td width=60% align=center>$rowjos[registerDate]</td></tr>"; // Add script for lead only view age. Team Member, field is hidden. Lead sees birthdate and/or age and a YES/NO if age matches. If not, lead will email user with ID verification e-mail, to verify age before assignments occur. echo "<tr><td width=40% align=right><strong>Age</strong></td><td width=60% align=center>$rowteam[age]</td></tr>"; }} echo "</table>"; } else { echo "Invalid URL. Registration does not exist"; } ?> This code is included within this page: viewregistration.php <?php session_start(); $user_id = $_SESSION['user_id']; $uid = $_GET['u_id']; $appid= $_GET['appid']; include ("db.php"); $get = mysql_query ("SELECT * FROM registrations WHERE u_id = $uid AND appid=$appid", $link2); echo $get; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title>Nuke Ice By ThemeKings</title> <link rel="stylesheet" type="text/css" href="nuke-ice.css" /> </head> <body> <div id="wrapper"> <div id="banner"> <div id="banner-edit"></div> </div> <div id="container"> <?php include ("sidebar.php"); ?> <div id="col-2"> <?php $uid = $_GET['uid']; $appid= $_GET['appid']; ?> <div class="CntBox"> <div class="CntHead"> <div class="CntHeadInfo">User Information</div> </div> <div class="CntFill"> <div class="CntInfo"> <?php include ("./source/userinfo.php"); ?> </div> </div> <div class="CntFooter"></div> </div> I included this bit of code so you can see some of the variables that were assigned in another file. Quote Link to comment https://forums.phpfreaks.com/topic/251856-problems-with-fetch-array/ Share on other sites More sharing options...
MasterACE14 Posted November 27, 2011 Share Posted November 27, 2011 if $uid or $appid is not set, then that would stop your queries from producing any results. Add or die(mysql_error()); at the end of the queries while debugging to see what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/251856-problems-with-fetch-array/#findComment-1291484 Share on other sites More sharing options...
doc4414 Posted November 27, 2011 Author Share Posted November 27, 2011 But the query IS producing results. It is selecting the right spot in the database (in this case the assign_id column where appid=$appid and uid=$uid. The output is fine. But why is the output causing the rest of the code to crash. I added that at the end of the query, no errors produced. It is the mysql_fetch_array while loop that is causing problems. But this is the only place it is causing problems. There is the same type of syntax later in the code that doesn't cause any problems. The query: $get_info = mysql_query ("SELECT * FROM registrations WHERE u_id=$uid AND appid=$appid" , $link2)or die(mysql_error()); 2 lines of code that are doing it.... //Begin Trouble Code while ($check = mysql_fetch_array($get_info)) echo $check['assign_id']; //End Trouble Code // Code kills here, for some reason.... Proper assign_id displayed, but it kills script. echo $check['assign_id']; The output on this is 71 (as seen in the picture, which is correct). Quote Link to comment https://forums.phpfreaks.com/topic/251856-problems-with-fetch-array/#findComment-1291520 Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2011 Share Posted November 27, 2011 It looks as thought the rest of the display is conditional upon $count >= 1. It seems counter intuitive that the value would be 0, but just to make sure, echo $count and see if its value is one or greater. You should at least get the user information block displayed if the conditional evaluates to TRUE. Also, and I know it's a long shot, but check the page source for the values to be sure it isn't somehow being hidden with the CSS. Quote Link to comment https://forums.phpfreaks.com/topic/251856-problems-with-fetch-array/#findComment-1291608 Share on other sites More sharing options...
doc4414 Posted November 28, 2011 Author Share Posted November 28, 2011 None of the above worked, however, I did fix it. I had a separate array linking to the same query, I merely renamed a query so there was only 1 unique array being defined per query and my script finished. Thanks for all the help! Doc Quote Link to comment https://forums.phpfreaks.com/topic/251856-problems-with-fetch-array/#findComment-1292008 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.