Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-11-2006, 07:34 AM
MuNKyonline's Avatar
WebProWorld Veteran
 

Join Date: Jun 2004
Location: Suffolk, England
Posts: 790
MuNKyonline RepRank 2
Default I need a php show html link script please

I want to be able to only display a link if a certain value is present in my database.

I've made the option 1 or 2. I only want the link to appear if the option is equal to 1.

Any ideas on how I could do this? I probably need to give more info than this!

Any help will be greatly appreciated!
Reply With Quote
  #2 (permalink)  
Old 01-11-2006, 05:20 PM
WebProWorld Pro
 

Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

Yep.. a lil more information would be nice.. ;)
language used?
database used?

Are you building a list.. or are you going to put the link inline with content? Like linking a keyword?

But here is some ugly code using php and mysql..
to build a list..

<?
$linkSQL= mysql_query("SELECT * from links where live='1'",$dblink)OR die(mysql_error());

While ($result=mysql_fetch_object($linkSQL)){
echo "<a href=\"$result->linkURL\">$result->linkTitle</a>
}
?>
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #3 (permalink)  
Old 01-12-2006, 09:35 AM
MuNKyonline's Avatar
WebProWorld Veteran
 

Join Date: Jun 2004
Location: Suffolk, England
Posts: 790
MuNKyonline RepRank 2
Default

I'm using PHP and a mySQL database. I've got a column (profile) in a table called tblcustomerdetails. The profile will only include a value of 1 or 2. I only want a link to appear on the page if the value is equal to 1, otherwise I dont want the link to be there at all.

I really do not know programming and am using the built in features of Dreamweaver MX and some plugins to be able to make a website. It's quite good so far, i've made a login and a form that inputs data into the database. The page then displays this information but I only want some of the entries to have a 'more details' link.

Thanks for your help Steve0, hopefully i've been a bit more clear now =)
Reply With Quote
  #4 (permalink)  
Old 01-13-2006, 03:09 AM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

Steve0 had it in his example, if you check for the existence of a 1 in the database using the sql statement.

However, if you want to show the link if it is a one, but show plain text or something else if it is not a 1, then you can do an if else statement:

Code:
if($sqlresult == 1)
{
echo "<html code to display link here>";
}
else
{
echo "<html code to display other info here>";
}
Of course, you need to make sure you have your sql connection setup and that you change it to the following on the select statement

Code:
$sql = "SELECT * FROM profile.tblcustomerdetails";
This pulls all the rows, and then you can step through them using the if and adjust the content accordingly...you still use the while statment, but you embedd the if statement within the while.
Reply With Quote
  #5 (permalink)  
Old 01-13-2006, 04:32 AM
MuNKyonline's Avatar
WebProWorld Veteran
 

Join Date: Jun 2004
Location: Suffolk, England
Posts: 790
MuNKyonline RepRank 2
Default

Right I see now, i'll give both of your examples a try and see where I get to. One other question though, I don't want anything at all to appear if it doesnt equal 1. Do I need to write anything specific to end the script without adding any code to the page?

Thanks a lot for all your help =)
Reply With Quote
  #6 (permalink)  
Old 01-13-2006, 01:34 PM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

Quote:
Yep.. a lil more information would be nice.. ;)
language used?
database used?

Are you building a list.. or are you going to put the link inline with content? Like linking a keyword?

But here is some ugly code using php and mysql..
to build a list..

<?
$linkSQL= mysql_query("SELECT * from links where live='1'",$dblink)OR die(mysql_error());

While ($result=mysql_fetch_object($linkSQL)){
echo "<a href=\"$result->linkURL\">$result->linkTitle</a>
}
?>
As already stated the above solution is the one to use for your problem. The SQL statement will only pull entries from your database that have the value of 1, so nothing written if the value doesn't equal one.

mike
Reply With Quote
  #7 (permalink)  
Old 01-16-2006, 08:50 AM
MuNKyonline's Avatar
WebProWorld Veteran
 

Join Date: Jun 2004
Location: Suffolk, England
Posts: 790
MuNKyonline RepRank 2
Default

Can someone please explain to me what I need to change to make this work for me? I keep changing bits to suit my database and the page wont load at all now. It's just a plain white page!

Could someone please break the whole thing down so I can understand what each part does? ALso am I supposed to put this whole block of code where I want the link to appear?

<?
$linkSQL= mysql_query("SELECT * from links where live='1'",$dblink)OR die(mysql_error());

While ($result=mysql_fetch_object($linkSQL)){
echo "<a href=\"$result->linkURL\">$result->linkTitle</a>
}
?>
Reply With Quote
  #8 (permalink)  
Old 01-17-2006, 12:34 AM
WebProWorld Pro
 

Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

<? //invoke php processor

$dbhost="localhost"; //connect info for db
$dbuser="fu"; //username
$dbpasswd="bar"; //password
$dbname="mydbname"; /database that has the tables you want to use
$dblink = mysql_connect("$dbhost","$dbuser","$dbpasswd"); //connection info

mysql_select_db("$dbname",$dblink); //another function


$linkSQL //holds the 'answer' to the query
mysql_query //php's mysql function to talk to the db

SELECT * from links where live='1' //retrieve all fields from the db where the field named live is equal to 1

$dblink //variable to hold the db connection information

OR die(mysql_error()); //if the function fails.. say why


While ($result=mysql_fetch_object($linkSQL)){ //As long as there is information in $linkSQL keep doing what is in the loop..

echo "<a href=\"$result->linkURL\">$result->linkTitle</a> //this is repeated for every record that matched the criteria in the query
} //end of loop
?> //end of php processing

You only need to call the query once..
"mysql_fetch_object" is like an array all the information is in it.. and pops it out in order..
so you can call that several times.. or use a loop.

If you send me your HTML, I take a look at it and show you where the code would go..

Think of it like crack, the first one will be a freebie :)
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #9 (permalink)  
Old 01-17-2006, 01:50 PM
MuNKyonline's Avatar
WebProWorld Veteran
 

Join Date: Jun 2004
Location: Suffolk, England
Posts: 790
MuNKyonline RepRank 2
Default

Thanks very much for that Steve0, that makes a lot more sense to me now! I havent had time to have another go at it yet. I'll post here when I have and i'll let you know how i've got on =)
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0