Jump to content

[SOLVED] Auto linking


lordphate

Recommended Posts

okay so i'm tryin go to do a auto link thing and i'm running into some problems with my mysql statements

 

$sql_query = "SELECT * FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());
$result = mysql_fetch_assoc($result);

foreach($result as $res){
$res["tag"] = $tag;
$res["link"] = $link;
}
echo "Test".$tag;

$keyword_array = array(
$tag => $link,

);

Link to comment
Share on other sites

What are you trying to do exactly, you did not really explain anything. Just looking at that one suggestion is this:

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$tag] = $link;
}

echo '<pre>' . print_r($keyword_array) . '</pre>';
?>

Link to comment
Share on other sites

What i'm trying to do is pull tag and link from the tags table

Then assign EACH "tag" and "link" as $tag and $link

 

here's the original array

$keyword_array = array(
"security" => "http://myscripts.itsp.info/security",
"technology" => "http://myscripts.itsp.info/technology",
"passport" => "http://myscripts.itsp.info/passport",
"state department" => "http://myscripts.itsp.info/state department",
"bruce" => "http://myscripts.itsp.info/bruce",
"radio frequency" => "http://myscripts.itsp.info/radio frequency"
);

Link to comment
Share on other sites

Crap, my bad another typo on my part.

 

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['tag']] = $row['link'];
}

echo '<pre>' . print_r($keyword_array) . '</pre>';
?>

 

Run that and see what happens.

Link to comment
Share on other sites

That is just a dump of the array. Try this maybe:

 

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now.
    $lastTag = $row['tag'];
}

echo '<a href="' . $keyword_array[$lastTag] . '">' . $lastTag . '</a><br />';
echo 'Array Structure<br /><pre>' . print_r($keyword_array) . '</pre>';
?>

 

Link to comment
Share on other sites

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now.
    $lastTag = $row['tag'];
}

foreach ($keyword_array as $tag => $link) {
    echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />';
}
?>

 

www.php.net/foreach

Link to comment
Share on other sites

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now.
    $lastTag = $row['tag'];
}

foreach ($keyword_array as $tag => $link) {
    echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />';
}
?>

 

would it be this or

 

$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['link']] = $row['tag'];
    $lastTag = $row['link'];
    $lastLink = $row['tag'];
}
foreach ($keyword_array as $lastTag => $lastLink ){
$keyword_array = array(
$lastTag => $lastLink
);     }

Link to comment
Share on other sites

It would be what I posted above. I do not understand where you are getting at with trying to re-define the keyword array? That makes no sense at all. the lasttag and lastlink are not required, just something created for testing.

 

<?php
$sql_query = "SELECT tag, link FROM tags";
$result = mysql_query($sql_query) or die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
    $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now.
}

foreach ($keyword_array as $tag => $link) {
    echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />';
}
?>

Link to comment
Share on other sites

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.