Jump to content

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>

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.