PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 16th, 2004, 08:16 AM
izzyg izzyg is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 izzyg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problems with php script

Hi

Im new to php and am having a few problems using a php script to retrieve information from a database and put it into a table.

I need to retrieve 4 values from the database, one of which I need to apply a link to, to link to a more info page and therefore I need to keep it separate from the other 3 fields.

The script below shows how I have separated this field from the other 3 fields using two separate select statement.


<?php

$host= 'host' ;
$user= 'user' ;
$passwd= 'passwd' ;
$database= 'database' ;
$connect= mysql_connect($host, $user, $passwd) ;
$table_name= 'table' ;
$query= "SELECT company_name, service_type, town_city FROM $table_name" ;
$queryid= "SELECT link_id FROM $table_name" ;
mysql_select_db($database) ;
$results_id = mysql_query($query, $connect) ;
$results_id_link = mysql_query($queryid, $connect) ;
if ($results_id) {
if ($results_id_link) {
print '<table width="280" cellpadding="0" cellspacing="0">' ;
print '<th class="verd9ptbold" align="left">Company name<th class="verd9ptbold" align="left">Service type<th class="verd9ptbold" align="left">Location <th class="verd9ptbold" align="left">More info' ;
while ($row_link = mysql_fetch_row($results_id_link)){
while ($row = mysql_fetch_row($results_id)){
print '<tr class="verdana_10pt_grey" height=\"60\">' ;
foreach ($row as $field)
print "<td>$field</td>" ;
foreach ($row_link as $field_link)
print "<td width=\"50\"><a href=\"search_links_details.php?=$field_link\">more info</a><br>\n</td>" ;
print '</tr>' ;
}}}}
else { die ("Query=$query failed!") ; }
mysql_close($connect) ;
?>


The problem is, while the first 3 values (those that are put into the $row variable) are all taken from the database and listed, the value that is separated (put into the $row_link variable) just repeats the first value from this field for all of the records of the $row variable

You can see what I'm trying to do at;

URL

Can anyone tell me how to change this code to make it work??

Thanks

Reply With Quote
  #2  
Old January 16th, 2004, 08:22 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You shouldn't need two queries for this. Just let your logic handle separating the link out. Only print what you need to at a given time.

Reply With Quote
  #3  
Old January 16th, 2004, 04:37 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i would have the link information all in one database corresponding with the company.
PHP Code:
//database open here
$query"SELECT company_name, service_type, town_city FROM $table_name" ;
$resultmysql_query($query) ;
echo 
"<table>
            <tr>
                 <td>
                    <strong>Company Name</strong>
                </td>
                <td>
                    <strong>Service Type</strong>
                </td>
                <td>
                    <strong>Location</strong>
                </td>
                <td>
                    <strong>More Info</strong>
                </td>
            </tr>"
;
while(
$row=mysql_fetch_array($result)){
    
$compName=$row['company_name'];
    
$service=$row['service_type'];
    
$place=$row['town_city'];
    
$link=$row['link'];
    echo 
"<tr>
            <td>
                $compName
            </td>
            <td>
                $service
            </td>
            <td>
                $place
            </td>
            <td>
                $link
            </td>
        </tr>"
;
}
    echo 
"</table>"


this should give u the table you seeked. Just for future scripts try to keep everything neat and organized, because before i thought i didnt need it but when u organize yourself and your thoughts everything is much easier to accomplish hope this works

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problems with php script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway