SitePoint Sponsor |
|
User Tag List
Results 1 to 24 of 24
-
Jan 17, 2005, 08:30 #1
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
MySQL database for web links !!!!
I want to create a database with mySQL that has links and a description of the link aswell, but i can't seem to figure out how do i make the link from the database an active link using PHP, i'm using PHP/mySQL - obviously
Help is appriciated
Thanks!
-AlBERT
-
Jan 17, 2005, 09:37 #2
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
anyone??
-
Jan 17, 2005, 11:17 #3
- Join Date
- Aug 2000
- Location
- Houston, TX, USA
- Posts
- 6,455
- Mentioned
- 11 Post(s)
- Tagged
- 0 Thread(s)
Well, you would need to create a table with four fields:
Code:CREATE TABLE links ( link_id int(5) not null auto_increment, link_title varchar(100) not null, link_loc varchar(100) not null, link_desc text not null, primary key(link_id) )
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
-
Jan 18, 2005, 07:08 #4
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I already have that done, i have already create a table with the fields, id, description, url, and alt. But i want to be able to get all the links in the database from the first till the last and have them ordered into an HTML table on my site, dynamicilly, but i want the links to be active meaning, i want them to work, which is what i can't do!!!!
-
Jan 18, 2005, 07:36 #5
Simply wrap the url column in the HTML link tag (<a href="url" title="alt">Description</a>
-
Jan 18, 2005, 08:00 #6
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<a href="url" title="alt">Description</a>
so would this be something like this: <p>click here: <a href="<?php echo $row_links['id']; ?>">HERE</a> </p>???
-
Jan 18, 2005, 08:16 #7
the initial 'click here:' text is not required
the 'HERE' text should be replaced with the contents of the description field.
the $row_links['id'] should probably be $row_links['ur'] assuming the 'utl' field contains the URL
-
Jan 18, 2005, 08:19 #8
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
doesn't seem to work, would be able to upload a working example or give me a link to a working example????
-
Jan 18, 2005, 08:29 #9
- Join Date
- Jun 2004
- Location
- Reading, UK
- Posts
- 970
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by user_A
eg:
PHP Code:$url = 'http://www.example.com' ;
$desc = 'This is an example description' ;
$alt = 'This is the alt string' ;
echo "<a href=\"$url\" alt=\"$alt\">$desc</a>" ;
Mike
-
Jan 18, 2005, 08:34 #10
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok that works fine
-
Jan 18, 2005, 08:38 #11
- Join Date
- Jun 2004
- Location
- Reading, UK
- Posts
- 970
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Good. Are you okay getting the data out of the database?
Mike
-
Jan 18, 2005, 08:41 #12
try this code
PHP Code:// I assume that you have connected to the MySQL server
// and have selected the correct database
// select the columns you require from the database
$sql = 'SELECT'
. ' url, description, alt'
. ' FROM '
. ' links' // this is the name of your table
;
// run the query
$result = mysql_query($sql) or die('Failed to execute ' . $sql . ' due to ' . mysql_error());
$start_link = '<a href="';
$end_link = '</a>';
// read the data from the database
while ($row = mysql_fetch_***0c($result))
{
// build the link tag
$link = $start_link // start of link tag
. $row['url'] // URL
. '" title="' // title attribute
. $row['alt'] // title data from the database
. '">' // complete <a ...> tag
. $row['description'] // description from database
. $end_link; // close the anchor tag
// display the link tag
echo $link;
}
-
Jan 18, 2005, 08:50 #13
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Error: Parse error: parse error, unexpected '{' on line 35
<?php require_once('intranet_db.php'); ?>
<?php
mysql_select_db($database_intranet_db, $intranet_db);
$query_weblinks = "SELECT * FROM media";
$weblinks = mysql_query($query_weblinks, $intranet_db) or die(mysql_error());
$row_weblinks = mysql_fetch_assoc($weblinks);
$totalRows_weblinks = mysql_num_rows($weblinks);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body bgcolor="#CCCCCC">
<?php // I assume that you have connected to the MySQL server
// and have selected the correct database
// select the columns you require from the database
$sql = 'SELECT'
. ' url, description, alt'
. ' FROM '
. ' links' // this is the name of your table
;
// run the query
$result = mysql_query($sql) or die('Failed to execute ' . $sql . ' due to ' . mysql_error());
$start_link = '<a href="';
$end_link = '</a>';
// read the data from the database
while ($row = mysql_fetch_***0c($result))
{
// build the link tag
$link = $start_link // start of link tag
. $row['url'] // URL
. '" title="' // title attribute
. $row['alt'] // title data from the database
. '">' // complete <a ...> tag
. $row['description'] // description from database
. $end_link; // close the anchor tag
// display the link tag
echo $link;
}
?>
</body>
</html>
-
Jan 18, 2005, 09:01 #14
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's my Db syntax:
CREATE TABLE `media_archive` (
`id` int(10) unsigned NOT NULL auto_increment,
`day` varchar(15) NOT NULL default '',
`month` varchar(15) NOT NULL default '',
`Year` varchar(15) NOT NULL default '',
`link` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM MAX_ROWS=255
Also see attached image:
-
Jan 18, 2005, 09:16 #15
Ok - I assume that you only want to display links where there is an actual link in the media_archive table.
PHP Code:$start_link = '<a href="';
$end_link = '</a>';
// select the columns you require from the database
$sql = 'SELECT'
. ' link'
. ' FROM '
. ' media_archive' // this is the name of your table
. ' WHERE'
. 'link IS NOT NULL'
;
// run the query
$result = mysql_query($sql) or die('Failed to execute ' . $sql . ' due to ' . mysql_error());
// read the data from the database
while ($row = mysql_fetch_assoc($result))
{
// build the link tag
$link = $start_link // start of link tag
. $row['link'] // URL
. '">' // complete <a ...> tag
. $row['link'] // description from database
. $end_link; // close the anchor tag
// display the link tag
echo $link;
}
-
Jan 18, 2005, 09:55 #16
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks that worked well, although i had to remove:
// select the columns you require from the database
$sql = 'SELECT'
. ' link'
. ' FROM '
. ' media_archive' // this is the name of your table
. ' WHERE'
. 'link IS NOT NULL'
;
I had to remove these two lines of code:. ' WHERE' . 'link IS NOT NULL' as i was getting an error saying that line one was NOT NULL or something like that, umm the links appear connected side by side horizontally, can i seperate them and for example can i have them arranged in an HTML table????
Thanks very much for the help
-
Jan 18, 2005, 10:23 #17
Oops -
change
PHP Code:. 'link IS NOT NULL'
PHP Code:. ' link IS NOT NULL'
You can arrange the links in any fashion you want to. Just add the appropriate HTML tags where you need them, and then echo the $link variable in the appropriate place.
-
Jan 18, 2005, 13:55 #18
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
WoW! Thank you so much! Mind if i ask, where could i possibly get more information or perhaps tutorials to further help me out with advanced code like the above?
-
Jan 18, 2005, 15:43 #19
More information - just keep looking in these forumns, especially the PHP forum for PHP stuff.
Also http://www.w3schools.com is another good site.
Search the PHP forum (lnik above) as there are more resources listed there
-
Jan 19, 2005, 03:13 #20
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What's wrong with this code?
<?php print "<table>";
$while ($row = mysql_fetch_array( $rs))
} <--- I keep getting an error on this line!! says unexpected syntax?
print "<tr>";
print "<td><a href=\"$row["url"]\" title=\"$row["alt"]>$row["description"]</a></td>";
print "</tr>";
{
print "</table>";
?>
-
Jan 19, 2005, 07:29 #21
-
Jan 19, 2005, 08:36 #22
- Join Date
- Mar 2004
- Location
- Vancouver, BC
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<?php print "<table>";
while ($row = mysql_fetch_array( $rs))
{
print "<tr>";
print "<td><a href=\"$row["url"]\" title=\"$row["alt"]>$row["description"]</a></td>";
print "</tr>";
}
print "</table>";
?>
after i fixed that, i get another error!
-
Jan 19, 2005, 09:37 #23
- Join Date
- Oct 2003
- Location
- St. Catharines, ON Canada
- Posts
- 1,708
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You are getting the error because you are using double quotes within a print statement that is double quoted.
You can't use "<tr> "$myvariable"</tr>" for instance but need to use "<tr> '$myvariable' </tr>"
After the initial open double quotes the next one you use closes the entire string. As far as PHP knows you are done with that line and is expecting nothing more except a semi-colon. You will need to tidy up any other areas of code you have where you are using double quotes around variables and whatnot.
-
Jan 19, 2005, 10:20 #24
- Join Date
- Nov 2001
- Location
- Dallas, Texas
- Posts
- 1,342
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey can you guys help me as well, since you're already here. ok i'm trying to display the id of the links stored within the mysql database.
for example http://dfhsdka/index.php?id=1 and so forth
i will try my best to explain what i want, so let's say they click on the link photos ok. i want it to display as photos?id=1 or ?id=photos and have it go the photos link. did i lose anyone lol
have a look at the code to see what i am doing wrong
PHP Code://pulling the links from the database
$sql_query = "SELECT * FROM site_links WHERE cat like 'main'";
//store the SQL query in the result variable
$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
{
echo ("{<a href=\"$row[2]\"> $row[3]</a>} ");
}
}
//if no fields exist
else
{
echo "no values in the database";
}
i love php
Bookmarks