User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,836 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,563 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 314 | Replies: 3
Reply
Join Date: Aug 2006
Posts: 31
Reputation: desiguru is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
desiguru desiguru is offline Offline
Light Poster

Display single sql data in php

  #1  
Apr 30th, 2008
I have a database called "App" and a table called appinfo.

I am able to connect to the database. It has only two entries since I am just trying to learn how to use php and sql together.

The first column in the appinfo table is called ID followed by 10 other columns. The ID is auto_increment.


So my question is how do i display one record's all of the columns in the database in a web page using php?
--
DG
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bali - Indonesia
Posts: 61
Reputation: rudevils is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
rudevils rudevils is offline Offline
Junior Poster in Training

Re: Display single sql data in php

  #2  
Apr 30th, 2008
This is a simple way to do it :
mysql_connect("yourhost","yourusername","yourpass");
mysql_select_db("yourdb");

$result = mysql_query(SELECT * FROM tablename LIMIT 1);
while($row = mysql_fetch_array($result)){ 
  $var1 = $row["yourfield1"];
  $var2 = $row["yourfield2"];
  .
  . 
  .
  $var10 = $row["yourfield10"];
}
echo "$var1 <br> $var2 .....  <br> $var10";
hope it help
If love is blind, why there's a bikini ??

Post your article at Bali Side Notes share your knowledge
Reply With Quote  
Join Date: Apr 2008
Posts: 3
Reputation: Doctoremote is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Doctoremote's Avatar
Doctoremote Doctoremote is offline Offline
Newbie Poster

Re: Display single sql data in php

  #3  
May 1st, 2008
I am a newbie to PHP but I am a VB programmer so it is not so strange. I had the same problem so here is my code displaying in a box on screen

  1. <?php
  2. $con = mysql_connect("connection","user","password");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. print "Connected to MySQL<br>";
  8.  
  9. mysql_select_db("yourdatabase", $con);
  10. $result = mysql_query("SELECT * FROM yourtable ORDER BY yourfield");
  11. // make box and name the fields in html
  12. echo "<table border='1'>
  13. <tr>
  14. <th>yourfield</th>
  15. <th>yourfield2</th>
  16. <th>yourfield3</th>
  17. </tr>";
  18. // fill box with data
  19. while($row = mysql_fetch_array($result))
  20. {
  21. echo "<tr>";
  22. echo "<td>" . $row['yourfield'] . "</td>";
  23. echo "<td>" . $row['yourfield2'] . "</td>";
  24. echo "<td>" . $row['yourfield2'] . "</td>";
  25. echo "</tr>";
  26. }
  27. echo "</table>";
  28.  
  29.  
  30. print "Please feel free to useTrevor<br>";
  31.  
  32. mysql_close($con);
  33. ?>


This code if you place your info in the sections in bold will work .. enjoy :-)
Last edited by peter_budo : May 1st, 2008 at 12:22 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Aug 2006
Posts: 31
Reputation: desiguru is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
desiguru desiguru is offline Offline
Light Poster

Re: Display single sql data in php

  #4  
May 1st, 2008
Thanks to both of you, I finally figured it out. Have a great day.
--
DG
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 7:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC