Jump to content

how to use a db data as html id ?


sasori

Recommended Posts

need help,

i have this table data (<td>) , it is being pulled from the db, and it appears like this in my code

<td><?php echo $row->title; ?></td> 

my question is, how will combine it with javascript ,let's say when someone onclick the title, the description will pop out , this description is being pulled from db.

 

if i will do it like this

<td id="title"><?php echo $row->title; ?></td> 

this is for only a single table data right? but what if the time goes by and more titles are being added on db ?

Link to comment
https://forums.phpfreaks.com/topic/191778-how-to-use-a-db-data-as-html-id/
Share on other sites

you havent included any code so here is an example of how to print out multiple field values from rows returned from the database

if ($dbConn = mysql_connect('user', 'pass', 'host'))
{
   $dbQuery = "SELECT * FROM table WHERE something = 'some text'";
   if ($dbResult = mysql_query($dbQuery))
   {
      while ($row = mysql_fetch_assoc($dbResult))
      {
         print($row['FieldName'].'<br/>'."\n");
      }
   }
   else
      print('Could not get result from query '.$dbQuery.'<br/>Error given: '.$mysql_error().'<br/>'."\n");
}
else
   print('Could not connect to db.<br/>'."\n");

ok sir, thanks but that's not the solutions, let me re-phrase my question.

 

How am I gonna make the $row->title,  pop its description $row->description when some random user clicks it ?

 

      <?php foreach($task->result() as $row): ?>
        <tr>
        <td><a href=#><?php echo $row->title; ?></a></td>
        </tr>
     <?php endforeach; ?>

it depends on what you mean by "pop its description".

 

if a tooltip would suffice for this "pop"ing, you can simply use a title attribute in the HTML:

<tr>
        <td><a title="<?php echo $row->description; ?>" href=#><?php echo $row->title; ?></a></td>
        </tr>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.