PHP Echo One Records Based Upon ID

I have seven elements absolutely positioned on a web page. Each one has a tooltip that is being queried by a dbase table (MySQL). What I want to do is to place inside each tooltip the echo for the heading and content based upon the ID in the row of the table.

My code is something like this:
<body>
<?php echo $row_getData[‘head_item’]; ?><br />
<?php echo $row_getData[‘item_description’]; ?>
</body>

Instead of me created seven queries for seven objects, is there a way for me to insert into the echo a specific ID to echo? Looping isn’t an option at this point, so that’s why I’m requesting this.

Thank you!

You should be able to do this in 1 query.

Going to need a bit more specific information about what you want to come out, and what your query currently looks like.

Thanks, Star Lion:

My query:

mysql_select_db($database_powerofx, $powerofx);
$query_getData = "SELECT * FROM powerofx";
$getData = mysql_query($query_getData, $powerofx) or die(mysql_error());
$row_getData = mysql_fetch_assoc($getData);
$totalRows_getData = mysql_num_rows($getData);

HTML:

<div class="tooltipContent" id="sprytooltip7">
<div class="secondback">
<div style="padding: 15px;">
<h1><?php echo $row_getData['head_item']; ?></h1>
<h2><?php echo $row_getData['subheading']; ?></h2>
<p><?php echo $row_getData['item_description']; ?></p>
<p class="morebutton"><a href="<?php echo $row_getData['item_link']; ?>">LEARN MORE</a></p>
</div>
</div>
</div>

What I want the results to look like is the heading, subheading, etc. to be retrieved from the dbase table based upon an ID without having to write seven different queries for each set of objects (I have six other <div>s each with their own ‘id’ for absolute placement on the web page); I tried a loop, but it doesn’t work when I have seven objects specifically placed on a web page, thus the request to somehow integrate the php echo based upon row ID.

For example, is there a way to <?php echo $row_getData[‘head_item’]where item_ID=‘1’; />? And so on and so forth?

Thanks for your reply!

okay. Lets… think this through.
$query_getData = “SELECT * FROM powerofx”;

Selects ALL data from the ENTIRE table. Not… ideal.

$row_getData = mysql_fetch_assoc($getData);

Now we’ve gotten the… first… row… only? O…kay…

$totalRows_getData = mysql_num_rows($getData);

And now we’ve counted the rows.

First of all; refine your query. If you arnt using all of the fields, dont select *, select the specific fields you want.
If you arnt using all of the rows, dont select them all. Add a WHERE clause.
Even if you ARE selecting them all, throw an ORDER BY clause in as well. Helps make sure you dont get unpredictable result.

Something more like…


<?php
mysql_select_db($database_powerofx, $powerofx);
$query_getData = "SELECT head_item,subheading,item_description,item_link FROM powerofx ORDER BY head_item";
$getData = mysql_query($query_getData, $powerofx) or die(mysql_error());
$totalRows_getData = mysql_num_rows($getData);

while($row_getData = mysql_fetch_assoc($getData)) {
?>
<div class="tooltipContent" id="sprytooltip7">
<div class="secondback">
<div style="padding: 15px;">
<h1><?php echo $row_getData['head_item']; ?></h1>
<h2><?php echo $row_getData['subheading']; ?></h2>
<p><?php echo $row_getData['item_description']; ?></p>
<p class="morebutton"><a href="<?php echo $row_getData['item_link']; ?>">LEARN MORE</a></p>
</div>
</div>
</div>
<?php
}
?>