Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Mysql data to html tables question
Old 02-27-2008, 10:42 PM Mysql data to html tables question
Junior Talker

Posts: 4
Name: David ONeill
Trades: 0
If this is an inappropiate request please let me know. Have searched forums and googled for tutorials, but not a php coder and don't really have time to learn it all so asking the experts. Need some simple code to accomplish the following:

Have mysql dbase (islandsbikesandb2) with one table (catalog).
6 fields in row:
id_num ( int, primary, auto increment)
mfg (varchar)
model (varchar)
type (varchar)
desc (varchar)
photo_path (varchar)

dbase and table created, Have php script to upload data via form for local admin . All works.

Need script to display contents of table(catalog) as follows:

Call: show_catalog.php? type=sometype mfg=somemfg

Return:

<html>
<body>


<table>
<tr>
<td>
for each record where type=sometype and mfg=somemfg , echo from (table=catalog)
(mfg) <br>
<img src=(photo_path) width=150px height=100> <br>
(model)
</td>
</tr>
</table>


Display: Table = 4 cells wide 4 rows high per page.As many pages as required to include all records in call.
Truncate if less than 16 matching records
No choice as to items per page for user.


A nice extra to avoid me having to shame myself by asking again:
In <td> above a link such as ><a href = show_item.php?><img src=(photo_path) width=150px height=100></a>
(eg; <a href=show_item.php? (variables to show record fields mfg, photo_path,desc for specific record))

Addition info:

Am using "includes" config.php and opendb.php in working scripts

configdb:

<?php
$dbhost = 'host_ip_address';
$dbuser = user_name';
$dbpass = 'pswd';
$dbname = 'db_name';
?>

opendb.php:

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>

As you can see, I know just enough PHP to be dangerous..... TIA for your help, and a few pointers to some GOOD tutorials or code snippets would be much appreciated.

CaptDavid
Savannah GA
USA
captdavid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-27-2008, 11:25 PM Re: Mysql data to html tables question
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Say the address was
http://example.com/catalog.php?type=...&page=THE_PAGE
PHP Code:
<?php $type $_GET['type'];
$mfg $_GET['mfg'];
$page $_GET['page'];
$pre_p $page-1;
$p $page+1;
$pre_p $pre_p*4;
$page $page*4;
$query "SELECT * FROM `catalog` WHERE type='$type' AND mfg='$mfg' LIMIT $pre_p,$page";
$result mysql_query($query);
$num mysql_num_rows($result);
$i=0;?>
<table>
<?php for($r=0;$r<4;$r++){
    echo 
"<tr>";
    for(
$c=0;$c<4;$c++){
        
$assoc mysql_fetch_assoc($result);
        echo 
'<td>'.$mfg.'<br><img src="'.$assoc['photo_path'].'" alt="" width="150px" height="100px"><br>'.$assoc['model'].'</td>';
        
$i++;
        if(
$i==$num){break;}
    }
    echo 
"</tr>";
    if(
$i==$num){break;}
}
?>
</table>
<p><a href="<?php echo $p;?>">Next Page</a></p>
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-28-2008, 12:01 AM Re: Mysql data to html tables question
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Nice help Arenlor! I was off writing I have had it with tards who don't use tags! while you were answering this. It will help, however, to check out http://www.webmaster-talk.com/php-fo...injection.html as your code allows for SQL injection and after you've been so nice to me, I'd hate to see you hacked by a SQL injection.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Mysql data to html tables question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19496 seconds with 12 queries