Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

While statement Not Working

Featured Replies

It has the bio_id of the wrestler and what it's supposed to do is get the manager_id and then take it to the efed_bio table and match that to the same integer and when it finds a match record then get that person's charactername and if there is a 0 for the value inside of manager_id then it says "N/A"

 

function getWrestling($style, $id) {
$id=mysql_real_escape_string($id);
if ($style=='singles') { 
$query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.manager_id = bio.id) WHERE ebw.bio_id = '$id'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
           <tr class="biotablerowb">
               <td class="biotableheadingb">Manager/Valet:</td>
               <td class="biotabledatab"><?php if (strlen ($row['manager']) < 1) {     print "N/A"; } else { print $row['manager'];}?></td>
           </tr>

           <tr class="biotablerowb">
               <td class="biotableheadingb">Finisher:</td>
               <td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) {     print "N/A"; } else { print $row['finisher'];}?></td>
           </tr>

           <tr class="biotablerowb">
               <td class="biotableheadingb">Setup:</td>
               <td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) {     print "N/A"; } else { print $row['manager'];}?></td>
           </tr>

           <tr class="biotablerowb">
               <td class="biotableheadingb">Entrance Music:</td>
               <td class="biotabledatab"><?php if (strlen ($row['music']) < 1) {     print "N/A"; } else { print $row['music'];}?></td>
           </tr>
       </table>    
<?php } }?>

At a quick glance it looks ok. Do you get any error messages?

 

Only thing I did notice, you have quotes around the $id in the WHERE clause. I'd assume $id is a number, if so you don't need to have quotes around it.

 

WHERE ebw.bio_id = $id";

 

Might be worth trying the SQL query in phpmyadmin or on the command line to see if it works (with the join etc).

Try this. It seems you were missing the closing curly brace ("}") for the line, "function getWrestling($style, $id) {"

 

note: remember that tabs and white-space are your best friends in coding ;)

 

<?php
function getWrestling($style, $id) {

$id=mysql_real_escape_string($id);

if ($style=='singles') { 

	$query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.manager_id = bio.id) WHERE ebw.bio_id = '$id'";
	$result = mysql_query($query) or die(mysql_error());

	while($row = mysql_fetch_array($result)) {

	echo('
		<h2>Wrestling</h2>
		<table class="biotable" cellspacing="10px">
			<tr class="biotablerowb">
				<td class="biotableheadingb">Manager/Valet:</td>
				<td class="biotabledatab"><?php if (strlen ($row['manager']) < 1) {     print "N/A"; } else { print $row['manager'];}?></td>
			</tr>

			<tr class="biotablerowb">
				<td class="biotableheadingb">Finisher:</td>
				<td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) {     print "N/A"; } else { print $row['finisher'];}?></td>
			</tr>

			<tr class="biotablerowb">
				<td class="biotableheadingb">Setup:</td>
				<td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) {     print "N/A"; } else { print $row['manager'];}?></td>
			</tr>

			<tr class="biotablerowb">
				<td class="biotableheadingb">Entrance Music:</td>
				<td class="biotabledatab"><?php if (strlen ($row['music']) < 1) {     print "N/A"; } else { print $row['music'];}?></td>
			</tr>
		</table>
		');

	} 

}

}
?>

@Jordan

 

Well spotted :)

 

Aha thanks. Some PHP errors just need a fresh pair of eyes to find them.

  • Author

I don't think its it because here's the entire function it its entirety.

 

function getWrestling($style, $id) {
$id=mysql_real_escape_string($id);
if ($style=='singles') { 
$query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ( ebw.bio_id = '$id') AND ( ebw.manager_id = bio.id)";
$result = mysql_query($query) or die(mysql_error());
echo $query;
while ($row = mysql_fetch_array($result)){
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($row['manager']) < 1) { 	print "N/A"; } else { print $row['manager'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Finisher:</td>
			<td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) { 	print "N/A"; } else { print $row['finisher'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Setup:</td>
			<td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) { 	print "N/A"; } else { print $row['setup'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($row['music']) < 1) { 	print "N/A"; } else { print $row['music'];}?></td>
		</tr>
	</table>	
<?php } }?>
<?php if ($style=='tagteam') { 

} ?>

<? if ($style=='manager') { 
$sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'";
$re = mysql_query($sql);
$row = mysql_fetch_assoc($re);
extract($row);
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($manager) < 1) { 	print "N/A"; } else { print "$manager";}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($music) < 1) { 	print "N/A"; } else { print "$music";}?></td>
		</tr>
	</table>
<?php } ?>

<? if ($style=='staff') { 
$sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'";
$re = mysql_query($sql);
$row = mysql_fetch_assoc($re);
extract($row);
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($manager) < 1) { 	print "N/A"; } else { print "$manager";}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($music) < 1) { 	print "N/A"; } else { print "$music";}?></td>
		</tr>
	</table>	
<?php } ?>

<? if ($style=='stable') { 

}
}

 

Aha thanks. Some PHP errors just need a fresh pair of eyes to find them.

I don't think its it because here's the entire function it its entirety.

 

function getWrestling($style, $id) {
$id=mysql_real_escape_string($id);
if ($style=='singles') { 
$query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ( ebw.bio_id = '$id') AND ( ebw.manager_id = bio.id)";
$result = mysql_query($query) or die(mysql_error());
echo $query;
while ($row = mysql_fetch_array($result)){
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($row['manager']) < 1) { 	print "N/A"; } else { print $row['manager'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Finisher:</td>
			<td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) { 	print "N/A"; } else { print $row['finisher'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Setup:</td>
			<td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) { 	print "N/A"; } else { print $row['setup'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($row['music']) < 1) { 	print "N/A"; } else { print $row['music'];}?></td>
		</tr>
	</table>	
<?php } }?>
<?php if ($style=='tagteam') { 

} ?>

<? if ($style=='manager') { 
$sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'";
$re = mysql_query($sql);
$row = mysql_fetch_assoc($re);
extract($row);
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($manager) < 1) { 	print "N/A"; } else { print "$manager";}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($music) < 1) { 	print "N/A"; } else { print "$music";}?></td>
		</tr>
	</table>
<?php } ?>

<? if ($style=='staff') { 
$sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'";
$re = mysql_query($sql);
$row = mysql_fetch_assoc($re);
extract($row);
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php if (strlen ($manager) < 1) { 	print "N/A"; } else { print "$manager";}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($music) < 1) { 	print "N/A"; } else { print "$music";}?></td>
		</tr>
	</table>	
<?php } ?>

<? if ($style=='stable') { 

}
}

 

Then have you got the exact error message you're getting? However as I already said you really need to work on formatting your code more neatly.

  • Author

I'm not getting an error message. Nothing is appearing for that function.

Do you have a PHP error log? Have you got errors turned on?

 

Also did you try running the query in phpmyadmin or cmd line?

 

I agree with code formatting thing... Try using an IDE/editor that indents for you perhaps.

  • Author

I have error reporting turned on and none are being reported and when I run it in phpmyadmin no results are being returned for the echoed query.

 

Do you have a PHP error log? Have you got errors turned on?

 

Also did you try running the query in phpmyadmin or cmd line?

 

I agree with code formatting thing... Try using an IDE/editor that indents for you perhaps.

I have error reporting turned on and none are being reported and when I run it in phpmyadmin no results are being returned for the echoed query.

 

Well then the problem is your query. Look up some documentation about what you want the query to do because to me it looks overly complicated.

Change your query to a LEFT JOIN

 

Looks like Jock's right to me :)

 

 

Edit:

 

Also, 'ON's can be dodgy. I'd check that.

  • Author

Okay this works, however, the value of manage_id needs to be compared to bio_id and then when it finds a matching row then get the bio.charactername field.

 

SELECT ebw.manager_id AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw LEFT JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ebw.bio_id = 6

  • Author

I came up with this and I'm getting closer however its saying that managerid is undefined.

 

function getWrestling($style, $id) {
$id=mysql_real_escape_string($id);
if ($style=='singles') { 
$query = "SELECT ebw.manager_id AS managerid, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw LEFT JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ebw.bio_id = $id";
$result = mysql_query($query) or die(mysql_error());
if($managerid != ''){
	$query = "SELECT * FROM `efed_bio` WHERE id = '$managerid'";
	$result = mysql_query($query);
	$row = mysql_fetch_assoc($result);
	$manager = $row['charactername'];
}
else{
	$manager = 'None';
}
while ($row = mysql_fetch_array($result)){
?>
<h2>Wrestling</h2>
<table class="biotable" cellspacing="10px">
		<tr class="biotablerowb">
			<td class="biotableheadingb">Manager/Valet:</td>
			<td class="biotabledatab"><?php echo $manager ?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Finisher:</td>
			<td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) { 	print "N/A"; } else { print $row['finisher'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Setup:</td>
			<td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) { 	print "N/A"; } else { print $row['setup'];}?></td>
		</tr>

		<tr class="biotablerowb">
			<td class="biotableheadingb">Entrance Music:</td>
			<td class="biotabledatab"><?php if (strlen ($row['music']) < 1) { 	print "N/A"; } else { print $row['music'];}?></td>
		</tr>
	</table>	
<?php } }?>

I'm pretty drunk right now but it looks like youre not actually pulling out a field called 'charactername'.

  • Author

That's always fun but its supposed to when it matches ewb.managerid to bio.id then get that row's charactername.

  • Author

$query = "SELECT ebw.manager_id AS managerid, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw LEFT JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ebw.bio_id = $id";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$managerid = $row['managerid'];  

 

This works however I need to figure out with the managerid if its 0 then that's when it puts None

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.