|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
|||
|
|||
|
i would have the link information all in one database corresponding with the company.
PHP Code:
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Problems with php script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|