Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Show link only if criteria is meet

Posted 29 Jul 2008 09:22:14
1
has voted
29 Jul 2008 09:22:14 Mike Scott posted:
I'm having a problem, I have a directory and there are paid listings and there are free listings, and one of the features that the paid listings have is web addresses for the business that is listed. in my database i have a "PaidListing" field and if its a paid listing then the field will have a "1", if its a free listing it would have a "0". so on the listing I only want to show the web site link if that listing has a "1" in the "PaidListing", but if it has a "0" in the "PaidListing" then i don't want the web site link to display.

any help would be great, thanks in advance

Mike

Edited by - KurveMedia on 29 Jul 2008 09:22:35

Replies

Replied 29 Jul 2008 21:05:32
29 Jul 2008 21:05:32 Georgi Kralev replied:
Hi Mike,

The PHP code for doing it may look like this:

<?php
// Make a MySQL Connection
// Replace mysql_username and mysql_password with your real username and password
mysql_connect("localhost", "mysql_username", "mysql_password" or die(mysql_error());
//Replace mysql_database with your database
mysql_select_db("mysql_database" or die(mysql_error());

// Get all records where PaidListing is set to 1 from "mysql_table" table
// Replace mysql_table with your table
$result = mysql_query("SELECT * FROM mysql_table WHERE PaidListing=1"
or die(mysql_error());

// Print out the web addresses in table
echo "<table border='1'>";
echo "<tr> <th>Listings</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
// Replace web_address_field with your field that contains the web address
echo $row['web_address_field'];
echo "</td></tr>";
}
echo "</table>";
mysql_free_result($result);
?>

I hope this helps.

<b>Note: </b>The code is not tested. Therefore it may contain errors.

Regards,

Georgi Kralev

Homepage: gdkralev.googlepages.com
Replied 31 Jul 2008 01:19:03
31 Jul 2008 01:19:03 Mike Scott replied:
Georgi Kralev

Thanks for the reply, I don't think i explained my problem very well.

what i have is all listings on one page, meaning both free and paid listings are on the same page. but i only want the listings that are paid to display the web address. hope that clarifies some of the confusion.


Mike
Replied 02 Aug 2008 15:39:16
02 Aug 2008 15:39:16 Georgi Kralev replied:
Hi Mike,

I am not quite sure if this is your case, but if you build all listing with PHP you can just check for the PaidListing value and print web address only when the value is 1.

Regards,


Georgi Kralev

Homepage: gdkralev.googlepages.com
Replied 03 Aug 2008 04:48:26
03 Aug 2008 04:48:26 Mike Scott replied:
Georgi

Below is the code that im using to only show a link to google maps if it is a paid listing and it works perfect
<pre id=code><font face=courier size=2 id=code>

&lt;?php
if ($row_rsListing['PaidListing']&gt;0)
{
echo "&lt;a href=\"maps.google.com/maps?f=q&hl=es&q=
$row_rsListing[businessNumber],
$row_rsListing[BusinessStreet],
$row_rsListing[BusinessCity],
$row_rsListing[BizState],$row_rsListing[BusinessZip]\"&gt;
Ver el mapa&lt;/a&gt;";}
?&gt;


</font id=code></pre id=code>


So i modified the code to only display the link for the
company web address but im getting an error.

<pre id=code><font face=courier size=2 id=code>
&lt;?php
if ($row_rsListing['PaidListing']&gt;0)
{
echo " Sitio web:&lt;a href="$row_rsListing['WebAddress']\"&gt;$row_rsListing['WebAddress']&lt;/a&gt;";}

?&gt;
</font id=code></pre id=code>


any help would be great, this thing has been a pain its the only thing really holding back the launch of the site...LOL

Thanks in advance
Mike [code]

Edited by - KurveMedia on 03 Aug 2008 04:49:06

Edited by - KurveMedia on 03 Aug 2008 04:50:14
Replied 03 Aug 2008 19:47:54
03 Aug 2008 19:47:54 Georgi Kralev replied:
Mike,

It looks like you have not escaped all the quotes. Try the following:
echo " Sitio web:&lt;a href=\"$row_rsListing['WebAddress']\"&gt;$row_rsListing['WebAddress']&lt;/a&gt;";}

If it is not working you can try to build your string. For example like this:

echo " Sitio web:&lt;a href=".$row_rsListing['WebAddress']."&gt;".$row_rsListing['WebAddress']."&lt;/a&gt;";}

I hope this helps.


Georgi Kralev

Homepage: gdkralev.googlepages.com
Replied 03 Aug 2008 21:52:44
03 Aug 2008 21:52:44 Mike Scott replied:
Georgi

thanks, i will try this and let you know the outcome. I appreciate the help.

Mike
Replied 03 Aug 2008 23:28:12
03 Aug 2008 23:28:12 Mike Scott replied:
Georgi

that piece of code worked perfect for that section.

i tried using the same code but changing it a little to only have certain things show up if the listing is paid, but i keep getting errors. So if you could help me out with those that would be great and i would really appreciate it. Just let me know and i will post the code that I'm talking about and the error that I'm getting.

Thanks
Mike
Replied 04 Aug 2008 20:03:50
04 Aug 2008 20:03:50 Georgi Kralev replied:
No problem Mike. You can post your code and the error.
I can check it, when I have some spare time.

This is a dev community. This means that other people also visit it and could provide you with some assistence.
Therefore, if you have problems do not hesitate to share them <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Regards,

Georgi Kralev

Homepage: gdkralev.googlepages.com
Replied 07 Aug 2008 10:58:15
07 Aug 2008 10:58:15 Mike Scott replied:
Georgi

sorry about the delay getting back to you. I have been workin on multiple projects at once.. not a good idea..lol


Ok, my problem is. there is a profile page for each business owner, and it allows them to edit their information, but ,like the website, i don't want the text field for the website to show up if thier listing is a free listing and not a paid listing. below is the code that i have and below that is the error im getting

<pre id=code><font face=courier size=2 id=code>
&lt;?php
if ($row_rsListing['PaidListing']&gt;0)
{
echo "&lt;input name="WebAddress" type="text" id="WebAddress" value="$row_rsUser['WebAddress']
}
?&gt;
</font id=code></pre id=code>

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/content/l/a/t/latinolinx/html/testing/edit.php on line 332

any help would be great, thanks in advance

Mike
Replied 07 Aug 2008 22:01:30
07 Aug 2008 22:01:30 Georgi Kralev replied:
Hi Mike,

It looks like the string that you print is not correct.
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
echo "&lt;input name="WebAddress" type="text" id="WebAddress" value="$row_rsUser['WebAddress']
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Instead of above line try something like this:

echo"&lt;input name=\"WebAddress\" type=\"text\" id=\"WebAddress\" value=\"$row_rsUser['WebAddress']\" /&gt;";

Or

echo '&lt;input name="WebAddress" type="text" id="WebAddress" value="'.$row_rsUser['WebAddress'].'"/&gt;';

I hope this helps you.

Note: It worths looking at some PHP tutorials for working with strings. They will help you to resolve these kind of issues.

Regards,

Georgi Kralev

Homepage: gdkralev.googlepages.com
Replied 21 Aug 2008 07:08:34
21 Aug 2008 07:08:34 Mike Scott replied:
Georgi

thanks for the help that worked perfect.

I'm working on a new problem now.. the client decided to change something, so i gotta figure out how to do that. I was trying ti with JavaScript it didn't work, so i tried it with php.... Ha Ha

Mike
Replied 22 Aug 2008 20:26:25
22 Aug 2008 20:26:25 Georgi Kralev replied:
No problem Mike. I am glad I could help.

Wish you all the best in your new endeavour with PHP <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Best regards,


Georgi Kralev

Homepage: gdkralev.googlepages.com

Reply to this topic