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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264115
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264127
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264136
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264142
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264165
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264203
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
https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264209
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.