473,378 Members | 1,411 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,378 software developers and data experts.

Add link to search results (<a href="">)

250 100+
In my php page there is a search function and when user search it will display table containing search results. I want to add
Expand|Select|Wrap|Line Numbers
  1. <a href ..></a>
  2.  
. Because when user click one record I want to pass values to ajax page.
to those results. But my code is not working. Please help me.This is my code.
Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_array($result))
  2.     {
  3.     echo "<a href='javascript:void(0);' onclick=\"LookupVehicle('$VehicleNo','$VehicleType','$VehicleMake','$Price'); return false;\">";
  4.         $array = array('VehicleNo','VehicleType','VehicleMake','Price');
  5.         foreach ($array as $v)
  6.         $$v = $row[$v];?>
  7.  
  8.           <tr>
  9. <?php
  10.  
  11.                 foreach ($array as $v)
  12.                 echo "<td height=20 cursor: pointer;'> &nbsp;".$$v."</td>";
  13.         ?>
  14.         </a>
  15.          </tr>
  16.  
  17.     <?php }
  18.  
Oct 8 '09 #1
1 4936
Atli
5,058 Expert 4TB
Hey.

Not feeling particularly articulate today, so I just commented your code :-]
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. while($row = mysql_fetch_array($result)) 
  3. {
  4.     // Isn't this supposed to be *after* you crate the variables you are echoing?
  5.     // And why is the ending </a> somewhere way inside the <tr> tag?
  6.     echo "<a href='javascript:void(0);' onclick=\"LookupVehicle('$VehicleNo','$VehicleType','$VehicleMake','$Price'); return false;\">";
  7.  
  8.     // Why bother with this? You can just as easilly use
  9.     // "$row['VehicleNo']" as "$VehicleNo"
  10.     $array = array('VehicleNo','VehicleType','VehicleMake','Price');
  11.     foreach ($array as $v){
  12.         $$v = $row[$v];
  13.     }
  14.     // P.S. Note the addition of the brackets to your foreach loop.
  15.     // Always use brackets. Leaving them out is just sloppy.
  16.  
  17.     // No poing exiting the <?php block just to output 4 letters.
  18.     // Echo was created for a reason ;-)
  19.     echo "<tr>";
  20.  
  21.     foreach ($array as $v) {
  22.         echo "<td height=20 cursor: pointer;'> &nbsp;".$$v."</td>";
  23.     }
  24.     // Again, note the added brackets to the loop.
  25.  
  26.     // 9 letters this time. Still not worth exiting the PHP block ;-)
  27.     // What's with the random </a> here? Shouldn't it be up there with the
  28.     // rest of the <a> tag?
  29.     // Unless you are trying to make the entire row a link, in which case
  30.     // you should use the <tr> onclick event, not enclose the <tr> in a <a> tag.
  31.     echo "</a></tr>";
  32. }
  33. ?>
Oct 8 '09 #2

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

Similar topics

3
by: Nel | last post by:
Hi all, I have been searching for some clues as to how to show a substring from a database search. $pagetitle = "Page Title"; $pagetext = "This is <b>a typical</b> string that would be...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
4
by: Dica | last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still trying to wrap my brain around .net coding habits. in classic asp, if i wanted to show search results, i'd just post the...
1
by: sqlster | last post by:
I have a search page which renders results upon post back based on certain input criteria. Clicking on a link on a search result such as order number navigates to the order detail screen. What...
0
by: =?Utf-8?B?Qm9ubmll?= | last post by:
I have a basic ASP / Index Server search page. I have a web site contained in a subdirectory in the root of a main web site. What I’m trying to do is force the search page in the subdirectory,...
4
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link...
3
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank...
5
by: moorcroft | last post by:
Hi I have developed an application that people can use to search for planning applications. The way it works is that once search criteria has been selected and submit is hit, the server will save...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.