Jump to content

Recommended Posts

How do i add html to this:

 

<?php
$connect = mysql_connect("localhost","root","");
$dbname = 'share';
mysql_select_db($dbname);
if (!$connect)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM `users` WHERE `id`='$id' LIMIT 1";
$query = mysql_query($sql);
if(mysql_num_rows($query) > 0){

//display content
while ($row = mysql_fetch_assoc($query)) {

echo $row['username'];
echo $row['gender'];
echo $row['email'];


}
}else{
echo 'user does not exist';
}


mysql_close($connect);
?>

 

I want it so i can put each one ov these in a table

 

echo $row['username'];
echo $row['gender'];
echo $row['email'];

 

but if i do this:

 

<?php echo $row['username'] ?>

 

It dont work any help ?

 

James.

Link to comment
https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/
Share on other sites

hmm, suprised no one answered yet, very simple question, and nicely asked question.

 

Your code should work.

 

Try this and tell us what the "HTML SOURCE" output is (view page in browser, go to view->page source)

 

<?php
$connect = mysql_connect("localhost","root","");
$dbname = 'share';
mysql_select_db($dbname);
if (!$connect)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM `users` WHERE `id`='$id' LIMIT 1";
$query = mysql_query($sql);
if(mysql_num_rows($query) > 0){

//display content
while ($row = mysql_fetch_assoc($query)) {

print_r($row);
echo("\r\n<br />\r\n");

echo $row['username'];
echo $row['gender'];
echo $row['email'];


}
}else{
echo 'user does not exist';
}


mysql_close($connect);
?>

Upon re-reading your question, lol:

 

You would do something like:

 

<?php

// echo the table start.
echo("<table width='400'>");

while ($row = mysql_fetch_assoc($query)) {
        // this echos a row each time. with 3 columns in each row.
echo("<tr>
    <td width='150'>".$row['username']."</td>
    <td width='100'>".$row['gender']."</td>
    <td width='150'>".$row['email']."</td>
</tr>
");
}

// end the table.
echo("</table>");

?>

 

This should be what your looking for.

 


hmm, suprised no one answered yet

 

I'm sure you'll figure out why soon enough.

 

Would you mind letting everyone know?

Worked!,

 

Thankyou :),

 

And the reason they ignore me is because we had a disput in another thread :S,

 

But if im honest you would think that a Moderator would act more maturely but i guess not anyway thankyou very much for that mate helped alot,

 

James.

Yes i read your previous posts.

 

A question is a question, if you know the answer and can spare 2 minutes - answer it. If people are worried about wasting time then they should post CODE only, since explain how it should work takes much longer than solving it in 1 post with code..

 

Dont understand these things sometimes.

 

Anyway, please don't repsond im not getting involved ust laying the facts for everyone else. PM if u want to have a say.

 

--

 

I'm glad it worked, but make sure you understand "why" it works. Peace.

The problem is that he refuses to learn the basics so 5m from now he'll be asking for someone else to fish for him again instead of taking the time to learn how to fish.  It is not technically against the rules to try and bum answers off people, but we promote learning, not bumming for handouts.

Hey James, get a clue!

 

Your probably one of those people who goes around self diagnosing yourself with "ass-burgars". I seriously doubt you have it, instead, I think you have a bad case of mental retardation.

 

Go read a tutorial, get somewhat good, then ask for help. Quit trying to get spoon fed. All your code samples are awful. Learn to make useful comments (not "// some code"), and keep your stuff consistent.

 

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.