Forum Moderators: coopster
Here's what I have so far:
I connect to the database, and the script displays links based on my database. It displays links, and the links are in the format of "name" being the text of the link, and "link" being the actual URL.
<?
$user="*********";
$password="******";
$database="*******";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>
<?
$query="SELECT * FROM countries WHERE country_category='europe'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>European Countries</center></b><br><br>";
$i=0;
{
while ($row = mysql_fetch_array($result)) {
$str = '<a href="' . $row['country_link'] . '">' . $row['country_name'] . '</a><br />';
echo $str;
}
$i++;
}
?>
I need to do the following things:
1.Make the links target=blank, so when clicked they open in a new window.
2.Change the font, size, and color of the links
3. Make the script cutoff and create a new page if there are more then 10 links as a result.
If anyone can help me out on this, I would be greatful. Thanks.
1.Make the links target=blank, so when clicked they open in a new window.
Add target="_blank" to your <a> in the script.
2.Change the font, size, and color of the links
You can do this via CSS. If the link or that section is into own div with a class of "country", then you can style your links, for example
.country a
{text-decoration:none;
color:#ff0000; // colour red
font-family:arial, sans-serif;
font-size:12px;}{
.country a:hover
{color:#0000ff;} // makes the link turn blue on hover
Cant help you on the 3rd question though.
$str = '<a href="' . $row['country_link'] . '">' . $row['country_name'] . '</a><br />';
echo $str;
say
echo '<a href="' . $row['country_link'] . '" target="_blank">' . $row['country_name'] . '</a><br />';
if you want to split it into pages, you'll have two options:
a) get a count on all the links you have to show (e.g. "SELECT count(*) FROM table WHERE condition") and then do limited selects (e.g. SELECT * FROM table WHERE condition LIMIT 0, 10" for the first page, 0 being the offset, 10 the number of results you want) depending on the page the client requests.
b) how lazy people do it who don't have a huge number of pages to deal with: read all links into an array and just start at, say, the 10th link, print 10 and stop.
I have a new code, but it isn't working as I thought. The links aren't displaying in a list, and the 'next' and 'back' buttons don't seem to be working correctly.. maybe someone can take a look...
<?
$user="8888888888";
$password="8888888888";
$database="8888888888";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>
<?
$increment = 5;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$query="SELECT * FROM diy WHERE diy_category='interior' LIMIT ";
$query .= $page * $increment - $increment . ", " . $increment;
$result = mysql_query($query);
$i=0;
{
while($row = mysql_fetch_array($result))
{
echo '<a href="' . $row['diy_link'] . '"target="_blank">' . $row['diy_name'] . '</a> ';
}
$i++;
}
if($page > 1)
{
echo '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $page - 1 . '"> Back </a>';
}
echo '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $page + 1 . '"> Next</a>';
?>