Hello everyone ! I have problems with my tags script !! Please i need help with it : Code: function pokaziZnacke($tag) { global $db; $query = "SELECT * FROM news WHERE tags=$tag"; $znacke_rezultat = mysql_query ($query); /* prikaze znacke */ while ($row = mysql_fetch_array ($znacke_rezultat)) { $tags = htmlentities ($row['tags']); $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); echo "News which have this tag"; echo " ".$title." "; } } PHP: My warning say it's problem in line 17 which is : while ($row = mysql_fetch_array ($znacke_rezultat)) { PHP: Total error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/keglichh/public_html/mysite.com/functions/tags.php on line 17
Change $query = "SELECT * FROM news WHERE tags=$tag"; PHP: TO $query = mysql_query("SELECT * FROM news WHERE tags=$tag"); PHP:
this should be working now $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'");
Error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/keglichh/public_html/mysite.com/functions/tags.php on line 18 Line 18: while ($row = mysql_fetch_array ($znacke_rezultat)) { PHP: Total code: function pokaziZnacke($tag) { global $db; $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'"); $query = mysql_query($query); $znacke_rezultat = mysql_query ($query); /* prikaze znacke */ while ($row = mysql_fetch_array ($znacke_rezultat)) { $tags = htmlentities ($row['tags']); $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>')); echo "News which have this tag"; echo " ".$title." "; } } PHP:
function pokaziZnacke($tag) { $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'"); $query = mysql_query($query); if(!is_resource($query)){die('MySql must not be connected!');} /* prikaze znacke */ while ($row = mysql_fetch_assoc($query)) { $tags = htmlentities($row['tags']); $title = htmlentities($row['title']); $news = nl2br(strip_tags($row['newstext'])); echo "News which have this tag: ".$title; } } PHP:
function pokaziZnacke($tag) { $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'") or die(mysql_error()); $query = mysql_query($query); if(!is_resource($query)){die('MySql must not be connected!');} /* prikaze znacke */ while ($row = mysql_fetch_assoc($query)) { $tags = htmlentities($row['tags']); $title = htmlentities($row['title']); $news = nl2br(strip_tags($row['newstext'])); echo "News which have this tag: ".$title; } } PHP: OR then make sure your connected to your database !!
Hi! I am connect to database... function pokaziZnacke($tag) { global $db; $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'") or die(mysql_error()); $query = mysql_query($query); if(!is_resource($query)){die('MySql must not be connected!');} /* prikaze znacke */ while ($row = mysql_fetch_assoc($query)) { $tags = htmlentities($row['tags']); $title = htmlentities($row['title']); $news = nl2br(strip_tags($row['newstext'])); echo "News which have this tag: ".$title; } } PHP: Other function which need database is working and it's same: global $db;
you dont need to pull your DB connection into functions its a kinda SUPER global and therefore you dont need global.. run the last one i sen you and tell me the mysql error it should show
function pokaziZnacke($tag) { global $db; $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'"); $query = mysql_query($query) or die(mysql_error()); if(!is_resource($query)){die('MySql must not be connected!');} /* prikaze znacke */ while ($row = mysql_fetch_assoc($query)) { $tags = htmlentities($row['tags']); $title = htmlentities($row['title']); $news = nl2br(strip_tags($row['newstext'])); echo "News which have this tag: ".$title; } } PHP: that should tell you your error
Damn, what is that now You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1
theres to mysql_queries !! try do -> function pokaziZnacke($tag) { $query = sprintf("SELECT * FROM news WHERE tags = '%s'",mysql_real_escape_string($tag)); $query = mysql_query($query) or die(mysql_error()); if(!is_resource($query)){die('MySql must not be connected!');} /* prikaze znacke */ while ($row = mysql_fetch_assoc($query)) { $tags = htmlentities($row['tags']); $title = htmlentities($row['title']); $news = nl2br(strip_tags($row['newstext'])); echo "News which have this tag: ".$title; } PHP:
waaa oop is working nowww ! Thanx! Can you please explain me what did you do :$ Ok another question.. I just planned to start working on my tags system for my news.. OK problem is .. When i am adding news, i have input field for tags.. So i write them like that: tag,tag2 ... And now problem is.. Tags for this news are tag1,tag2 not tag1 and tag2 Well if you don't udnerstand me, i cannot get each tag from database.. So that my system will show tags and when you click on one tag it will show news with that tag. Now one of my news have these tags: testing,tags. So actually both tags are one record.. i want each tag after "," as one record which belong to news ID lol :d
//ok lets say u have a form with an input box named tags, on the add post functions you need to do summat like $Tags = trim($_POST['tags']); //now we want to split them up so we do this $SplitTags = array_walk(explode(',',trim($Tags)),'trim'); // this wil make all tags seperate and trim each one //then you have an aray of tags :P PHP:
The problem was that your query was running twice. $query = mysql_query("SELECT * FROM news WHERE tags='".mysql_real_escape_string($tag)."'"); $query = mysql_query($query) or die(mysql_error()); So the second $query is actually running mysql_query(mysql_query("SELECT * FROM NEWS WHERE tags='".mysql_real_escape_string($tag)."'"); That is not a valid query. If you changed the first $query to just: $query = "SELECT * FROM `news` WHERE `tags` = '$tag'"; It would also work. You do still want to escape $tag, however.