jamesxg1 Posted January 25, 2009 Share Posted January 25, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/ Share on other sites More sharing options...
uniflare Posted January 26, 2009 Share Posted January 26, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746135 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 hmm, suprised no one answered yet I'm sure you'll figure out why soon enough. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746136 Share on other sites More sharing options...
uniflare Posted January 26, 2009 Share Posted January 26, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746139 Share on other sites More sharing options...
jamesxg1 Posted January 26, 2009 Author Share Posted January 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746145 Share on other sites More sharing options...
uniflare Posted January 26, 2009 Share Posted January 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746147 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-746148 Share on other sites More sharing options...
aximbigfan Posted January 28, 2009 Share Posted January 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142408-solved-how-do-i-add-html-to-php/#findComment-748086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.