Current location: Hot Scripts Forums » Programming Languages » PHP » Manipulating arrays for display in HTML


Manipulating arrays for display in HTML

Reply
  #1 (permalink)  
Old 08-04-03, 03:42 PM
madsurfer007 madsurfer007 is offline
New Member
 
Join Date: Aug 2003
Location: Pretoria
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Manipulating arrays for display in HTML

Hi to all you PHP people.

I am in SA and PHP is not very big here.(YET) I've been doing programming now for 4 month's in php or any language for that matter.

My site is bizzindex.co.za.

My problem:

I need to manipulate array data that i get from the database to display on the HTML document where i want it to. My function is:
<?
function getrow( $table )

{
global $link;
$result = mysql_query( "SELECT * FROM $table order by category", $link );

if ( ! $result )
{
print "failed to open $table<p>";
return false;
}

while ( $row = mysql_fetch_row( $result ))

{

print "<tr><td><FONT size = 5 FACE=\"Sans Serif\" COLOR=\"#3d65ff\">
<a href = \"show_classified.php?bizz_id=$row[0].&" . SID . "\">
--->>$row[1]</a></td></tr>\n<br>";

}


}
?>

I am currently building a classifieds section and i dont want to display the category's like the bizzindex.php page on my website.

I need to place it left, center and right as the data comes out of the database. Can anyone point me in the direction of a function or method etc. I checked "foreach" and "while", dont see anything, or maybe i am missing it.
Reply With Quote
  #2 (permalink)  
Old 08-04-03, 10:39 PM
inkblot's Avatar
inkblot inkblot is offline
The Lonely Coder
 
Join Date: Aug 2003
Location: Ontario
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not sure I quite understand what you're asking. Is the problem a matter of how to place the data in columns on the HTML page?
__________________
where am i......
Reply With Quote
  #3 (permalink)  
Old 08-05-03, 12:31 PM
IndyTim IndyTim is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Indianapolis, Indiana USA
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Cool

If I understand your posting corrrectly, you want to read some data from a mysql table and display the returned data into a html table.

If this is correct, there are many different ways that you can do this. Here's one suggestion:

1. Using a standard query to the database table, pull your data.
2. While reading the returned records from the table, write the returned data to an array.
3. Close your mysql connection
4. Within your html, read the contents of the previous array into specific columns of your html table.

I'm attaching a snippet of some of my code from a script (note- I'm a fan of numerically indexed arrays)

$sq1="select fprog, fdesc from troster order by fprog";
$res1=mysql_query($sq1);
$ret1=mysql_num_rows($res1);
if($ret1>0)
{
$n=0;
while($r1=mysql_fetch_array($res1))
{
$aa[$n][0]=$r1['fprog']; #assigning field fprog to array aa[n][0]
$aa[$n][1]=$r1['fdesc']; #assigning field fdesc to array aa[n][1]
$n++;
}
}

mysql_close

_____

within your html you would read the contents of the array and display in the column associated with the specific field of the array like:

for($k=0; $k<(count($aa)); $k++)
{
print '<tr>';
print '<td>'.$aa[$k][0].'</td>'.'<td>.$aa[$k][1].'</td></tr>'."\n";
}

Hope this helps.

IndyTim
__________________
Believe those who are seeking the truth; doubt those who find it.
-Andr Gide
Reply With Quote
  #4 (permalink)  
Old 08-07-03, 08:26 PM
jv2222 jv2222 is offline
The Freshmaker
 
Join Date: Jun 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

ezSQL might make thigs simpler for you.

Cheers,
Justin
__________________
Author of <a href=http://www.hotscripts.com/Detailed/18290.html target=_blank>ezSQL</a> (makes life soooo easy when working with databases)
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Programmer Looking For Work. SeymourGuodo Job Offers & Assistance 5 10-16-03 03:39 PM
Script for picking the first HTML file out of a directory (with sorted HTML files) jelteveld Script Requests 0 08-16-03 01:30 PM


All times are GMT -5. The time now is 04:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.