Xtremer360 Posted February 25, 2011 Share Posted February 25, 2011 I finally got all my other problems answered however the query in the db works but it isn't echoing any of the values when there are values. <div id="roster" class="content"> <h1 class="pageheading">Singles Biographies</h1> <span class="minilinks"><a href="/roster/tag-team-roster">Tag Teams</a> | <a href="/roster/stable-roster">Stables</a> | <a href="/roster/manager-roster">Managers</a> | <a href="/roster/referee-roster">Referees</a> | <a href="/roster/staff-roster">Staff</a></span> <?php $query = "SELECT characters.shortName, characters.characterName, singles.height, singles.weight, singles.hometown FROM characters LEFT JOIN singles as singles ON characters.ID = singles.characterID WHERE characters.styleID = '1' AND characters.statusID = 1 ORDER BY characters.sortOrder"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $fieldarray = array('characterName','shortName','height','weight','hometown'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { $fieldlabel = $row[$fieldlabel]; } } ?> <div id="wrestler"> <div id="headshot"> <?php if (file_exists('/images/headshots/' . $shortName . '.png')) { print '<img src="images/headshots/' . $shortName . '.png">'; } else { print '<img src="images/headshots/default.png">'; } ?> </div> <div id="wrestler-info"> <div id="wrestler-info"><p><span class="rostername"><a class="biolinks" href="/bio?username=<?php echo $shortName ?>"><?php echo $characterName ?></a></span><br /> Height: <?php echo $singlesheight ?><br /> Weight: <?php echo $singlesweight ?><br /> Hometown: <?php echo $singleshometown ?><br /></p> </div> </div> </div> <div class="clear"></div> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/ Share on other sites More sharing options...
trq Posted February 25, 2011 Share Posted February 25, 2011 Where exactly are these variables defined? <div id="wrestler-info"><p><span class="rostername"><a class="biolinks" href="/bio?username=<?php echo $shortName ?>"><?php echo $characterName ?></a></span><br /> Height: <?php echo $singlesheight ?><br /> Weight: <?php echo $singlesweight ?><br /> Hometown: <?php echo $singleshometown ?><br /></p> </div> Assuming of course they are what your talking about. Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179422 Share on other sites More sharing options...
Xtremer360 Posted February 25, 2011 Author Share Posted February 25, 2011 I modified the code just a little but still not echoing it. When I run this query it shows up fine wiht the characterName and shortName and blank values for the height, weight, hometown rows but that's only because they are empty as of right now. <div id="roster" class="content"> <h1 class="pageheading">Singles Biographies</h1> <span class="minilinks"><a href="/roster/tag-team-roster">Tag Teams</a> | <a href="/roster/stable-roster">Stables</a> | <a href="/roster/manager-roster">Managers</a> | <a href="/roster/referee-roster">Referees</a> | <a href="/roster/staff-roster">Staff</a></span> <?php $query = "SELECT characters.shortName, characters.characterName, singles.height, singles.weight, singles.hometown FROM characters LEFT JOIN singles as singles ON characters.ID = singles.characterID WHERE characters.styleID = '1' AND characters.statusID = 1 ORDER BY characters.sortOrder"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $fieldarray = array('characterName','shortName','height','weight','hometown'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { $fieldlabel = $row[$fieldlabel]; } } ?> <div id="wrestler"> <div id="headshot"> <?php if (file_exists('/images/headshots/' . $shortName . '.png')) { print '<img src="/images/headshots/' . $shortName . '.png">'; } else { print '<img src="/images/headshots/default.png">'; } ?> </div> <div id="wrestler-info"> <div id="wrestler-info"><p><span class="rostername"><a class="biolinks" href="/bio?shortName=<?php echo $shortName ?>"><?php echo $characterName ?></a></span><br /> Height: <?php echo $height ?><br /> Weight: <?php echo $weight ?><br /> Hometown: <?php echo $hometown ?><br /></p> </div> </div> </div> <div class="clear"></div> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179426 Share on other sites More sharing options...
trq Posted February 25, 2011 Share Posted February 25, 2011 Those variables are not defined anywhere. I'm really not sure what you think your doing. Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179428 Share on other sites More sharing options...
Xtremer360 Posted February 25, 2011 Author Share Posted February 25, 2011 Well to me my code does this it takes each of the items that its SELECTING and puts them into an arrow and then for each item assigns it to a variable fieldlabel. Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179599 Share on other sites More sharing options...
samoht Posted February 25, 2011 Share Posted February 25, 2011 what thorpe is getting at is that you don't automatically have the query results as php variables. You need to set them as such or use $row['shortName'] etc instead of $shortName But this : $fieldarray = array('characterName','shortName','height','weight','hometown'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { $fieldlabel = $row[$fieldlabel]; } } makes no sense Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179608 Share on other sites More sharing options...
Xtremer360 Posted February 25, 2011 Author Share Posted February 25, 2011 So your saying I need to delete that? Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179610 Share on other sites More sharing options...
samoht Posted February 25, 2011 Share Posted February 25, 2011 Yes! It is not doing anything anyway. I suppose you could use extract() to get your mysql results into php var's but I wouldn't do that if you return more than one row from the db. Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179617 Share on other sites More sharing options...
trq Posted February 26, 2011 Share Posted February 26, 2011 What you seem to be trying to achieve but using the completely wrong syntax for is variable variables. That would be achieved using.... $fieldarray = array('characterName','shortName','height','weight','hometown'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { ${$fieldlabel} = $row[$fieldlabel]; } } However, I would never recommend such a method as variable variables are slow. use an array instead. Besides, if you are retreiving more than a single record your logic is still floored because you will only ever get the last record available. Quote Link to comment https://forums.phpfreaks.com/topic/228768-one-last-thing/#findComment-1179829 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.