Jump to content

Recommended Posts

I need help creating a link if a value set in my client table is set as 1.  I have a business directory that when a user clicks on a category, say Dining, it loads all the restaurants in my database.

 

Here is the code for that:

<?php
$prev_row ='';
echo '<table class=results>';
while($info = mysql_fetch_array( $data )) {
$letter = strtoupper(substr($info['name'],0,1));
if ($letter != $prev_row) {
	if($count % 3) {
		for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
		echo '</tr>';
		$count =0;
	}
	$prev_row = $letter;
	echo '<tr bgcolor=#e7e7e7><td colspan=\"3\"><font color=#993833><b>',$letter,'</b></font></td></tr>';
}
if ($count % 3 == 0) echo '<tr>';
$count++;
echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";
if ($count % 3 == 0) echo '</tr>';
}
if($count % 3) {
for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
echo '</tr>';
}
echo '</table>';
?>

 

 

Now I need to alter the above code so that if it is a paying customer the name of the business becomes a link and when the user clicks on the business name it takes them to a new page which will load more information about that business.  So my question is how do i fix that code to do that.  I have a column in the client table that is named paid and will be set to 1 if they are paying and 0 if they are not paying.  Figured that would be the easiest way.  Can anyone help me with how to do that?  Thanks.  (the name of the page it will take them to is client_detail.php)  I am guessing it will be an if statement or something around this area:

 

if ($count % 3 == 0) echo '<tr>';
$count++;
echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";

 

but still new to php and not sure how to set that up when it is already in an if statement.  Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/66006-solved-creating-a-link-if/
Share on other sites

In your query (which you don't show in that code) you will need to include "paid" in the SELECT clause (assuming you don't). After you have that, just make an if statement.

if ($info['paid'] == 1)
    echo "<td><a href=\"client_detail.php\">", $info['name'], '</a><br />Phone: ', $info['phone'], "</td>\n";
else
    echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.