Jump to content

Recommended Posts

Hi friends. I want to php code on how i can modify my retrieved database values from a particular table before echoing out. Please could you help me correct the code. Or if there is any better way of editing loop datas before printing out, please kindly drop the code for me. Thanks

 

<?php    
$q = "SELECT * FROM threads WHERE catid='2'";
 $get = $database->query($q) or die(mysql_error());
$row=mysql_fetch_row($get);

$value=$row['0']['title'];
$one='first value'; 
echo $value.$one;

$value=$row['1']['name'];
$two='second value'; 
echo $value.$two;

$value=$row['2']['category'];
$three='third value'; 
echo $value.$three;
?>

please if there is any better way of editing loop values from mysql database before printing out, please kindly drop the code for me. Thanks

if you query returns more than one record then you can use'd use a loop to iterate over the results, Example

// loop over the records returned by the query
while($row = mysql_fetch_assoc($result))
{
    $title    = $row['title'];    // get the title for current record
    $name     = $row['name'];     // get the name for current record
    $category = $row['category']; // get the category for current record


    echo "$title - $category - $name<br />";
}

But what are wanting to edit the values to?

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.