Jump to content

One last thing


Xtremer360

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.