473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do I display SQL query results in a repeating table?

Hi all,

This is my first post here, but i've lurked for a while.

I'm working on a website but have come across a major stumbling block in the code:

I've managed to structure the search query but have 2 problems:

I dont know how to code the results into the table, and make the table repeat itself 5 times per page (and recognise it needs a new page)

And I cant test the search query because i cant get the results to display.

If any one could answer 1 or more of these problems and/or correct any error's i've made I'd jump for joy, as i feel i've been fumbling in the dark for the last week or so.

Here's my code so far:
Expand|Select|Wrap|Line Numbers
  1. $connection = mysql_connect($hostname, $username, $password);
  2.     if (!$connection) {
  3.        die("A connection to the server could not be established");
  4.     }
  5.     //remember to select the database!
  6.     mysql_select_db($database) or die("Database could not be selected!");
  7.  
  8.     //get the values from the form
  9.     $MerchantType = $_POST["MerchantName"];
  10.     $County = $_POST["County"];
  11.  
  12.     // rows to return
  13. $limit=10; 
  14.  
  15.  
  16. // Build SQL Query  
  17. $query = "SELECT * FROM Testtable where County = '$county'  
  18.   ORDER BY MerchantType"; // EDIT HERE and specify your table and field names for the SQL query
  19.  
  20.  $numresults=mysql_query($query);
  21.  $numrows=mysql_num_rows($numresults);
  22. ?>
  23.  
  24. <?php
  25. echo "
  26. <html><body><table>
  27. <table border="1" bordercolor="#FFCC00" style="background-color:#FFFFFF" width="800" cellpadding="3" cellspacing="3">
  28. <tr>
  29. <td width="200" align="left" rowspan=5>Image</td>
  30. </tr>
  31. <tr>
  32. <td width="573" align="left">Name:</td>
  33. </tr>
  34. <tr>
  35. <td height="27" align="left">Telephone:</td>
  36. </tr>
  37. <tr>
  38. <td height="27" align="left">Website:</td>
  39. </tr>
  40. <tr>
  41. <td height="54" align="left">Description:</td>
  42. </tr>
  43. </table>
  44.  
  45. </html></body></table>;
  46. ?>
Thanks,
Sam
Nov 25 '09 #1

✓ answered by Alien

Why not do a while statement with mysql_fetch_array( ) ?

Expand|Select|Wrap|Line Numbers
  1. $counter = 1;
  2. $maxRows = 5;
  3. $query1 = "# SELECT * FROM Testtable where County = '$county'  
  4. #   ORDER BY MerchantType";
  5. <table>
  6. while($counter < $maxRows)
  7. {
  8.     $row_details = mysql_fetch_array($query1)
  9.  
  10. // each $row_details will have a row from the table, just output it onto a table.
  11.      // $row_details['col1'] will output the which you need to put in <td></td>. 
  12. }    
  13. </table>
  14.  
So you get first 5 rows this way. Do a bit of more programmiing using sessions to alter value of $counter and $maxRows to get your remaining tables.

3 4811
ak1dnar
1,584 Expert 1GB
Why don't you first have a look on the table pagination tutorials here.
Nov 26 '09 #2
Alien
61
Why not do a while statement with mysql_fetch_array( ) ?

Expand|Select|Wrap|Line Numbers
  1. $counter = 1;
  2. $maxRows = 5;
  3. $query1 = "# SELECT * FROM Testtable where County = '$county'  
  4. #   ORDER BY MerchantType";
  5. <table>
  6. while($counter < $maxRows)
  7. {
  8.     $row_details = mysql_fetch_array($query1)
  9.  
  10. // each $row_details will have a row from the table, just output it onto a table.
  11.      // $row_details['col1'] will output the which you need to put in <td></td>. 
  12. }    
  13. </table>
  14.  
So you get first 5 rows this way. Do a bit of more programmiing using sessions to alter value of $counter and $maxRows to get your remaining tables.
Nov 26 '09 #3
Thank you both so, so much for your help. I apologise for asking such a basic question.

I went to bed dreading this morning and another day of coding, now i'm able hit it head on.

Thanks again,

Sam
Nov 26 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: erica | last post by:
Hi, I am currently writing PHP code for some polling software. When someone votes, it stores their IP address in the database. From then on, they cannot vote in that particular poll, they only...
13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
3
by: matthewemiclea | last post by:
I am trying to display information in Access on a form that takes information from many different queries and puts them together on a spreadsheet or chart. Some specific info: The information I...
5
by: jim Bob | last post by:
Hi, Can someone help with a simple query? I have a table with the following. Firstname Lastname InterviewerID1 InterviewerID2 InterviewerID3 ...
5
by: PHPBABY3 | last post by:
Hi, 1. I have two SQL tables. I will call them employees and departments: EMP: LAST_NAME, FIRST_NAME, DEPTNM DEPT: NUM, NAME Input: text string FIND Output: the LAST_NAME, FIRST_NAME...
5
by: bruce24444 | last post by:
What I have is a database which tracks assigned files to a certain people which is generated by a form and then recorded into a table. Table are as follows “Staff” “Loss_Type” and...
1
by: bruce24444 | last post by:
First of all I'm new to the forum and am working on my first database. So far I think I've done not too bad but have hit a stumbling block for which I'm not sure how to get around. What I have is...
4
by: Yitzak | last post by:
Have a query that is arregated into crosstab query, it is working correctly. select Yes as selected from tblname or select true as selected from tblname Produces -1 ( vba value of True) in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.