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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

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

    In my php page there is a search function and when user search it will display table containing search results. I want to add
    Code:
    <a href ..></a>
    . 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.
    Code:
    while($row = mysql_fetch_array($result))
    	{
    	echo "<a href='javascript:void(0);' onclick=\"LookupVehicle('$VehicleNo','$VehicleType','$VehicleMake','$Price'); return false;\">";
    		$array = array('VehicleNo','VehicleType','VehicleMake','Price');
    		foreach ($array as $v)
    		$$v = $row[$v];?>
    	
    	  	<tr>
    <?php
    
    				foreach ($array as $v)
    				echo "<td height=20 cursor: pointer;'> &nbsp;".$$v."</td>";
    		?>
    		</a>
    		 </tr>
    		  
    	<?php }
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Not feeling particularly articulate today, so I just commented your code :-]
    [code=php]<?php
    while($row = mysql_fetch_arr ay($result))
    {
    // Isn't this supposed to be *after* you crate the variables you are echoing?
    // And why is the ending </a> somewhere way inside the <tr> tag?
    echo "<a href='javascrip t:void(0);' onclick=\"Looku pVehicle('$Vehi cleNo','$Vehicl eType','$Vehicl eMake','$Price' ); return false;\">";

    // Why bother with this? You can just as easilly use
    // "$row['VehicleNo']" as "$VehicleNo "
    $array = array('VehicleN o','VehicleType ','VehicleMake' ,'Price');
    foreach ($array as $v){
    $$v = $row[$v];
    }
    // P.S. Note the addition of the brackets to your foreach loop.
    // Always use brackets. Leaving them out is just sloppy.

    // No poing exiting the <?php block just to output 4 letters.
    // Echo was created for a reason ;-)
    echo "<tr>";

    foreach ($array as $v) {
    echo "<td height=20 cursor: pointer;'> &nbsp;".$$v. "</td>";
    }
    // Again, note the added brackets to the loop.

    // 9 letters this time. Still not worth exiting the PHP block ;-)
    // What's with the random </a> here? Shouldn't it be up there with the
    // rest of the <a> tag?
    // Unless you are trying to make the entire row a link, in which case
    // you should use the <tr> onclick event, not enclose the <tr> in a <a> tag.
    echo "</a></tr>";
    }
    ?>[/code]

    Comment

    Working...