Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am creating a CMS and have php creating a page. i have a while loop like this

while($row = mysql_fetch_array($results)) {
echo "some html code" . $row['name'];

its shortend but hopefully you get the point. i have the full thing in my page working just as it should and i wanted to move it to a function include as i want to reuse it. the problem is i do that and it stops working.

i did some testing and found that the function is getting the query result and after doing a var dump both were identical the problem comes when i try to assign it to an array. it comes back as false so in the above code, for example,

$row = false;

im toatly lost in this and if my explanation is confusing i appologise but i am a bit of a newbie i have tried searching but....i dont really know where to begin any thoughts.

share|improve this question
1  
First of all don't use mysql_* functions it's deprecated use mysqli_* php.net/manual/en/mysqli.error.php and see what errors you get – Sedz yesterday
i had seen that but thanx as for errors i get none the problem isnt with the mysql query to the database its fine its just when i try to use it as a function. – jaggysnake yesterday
please post your full code function – Sedz yesterday

2 Answers

the query you are doing is basically wrong, try posting exactly the code which you have in $query and then let us see the problem. also, it is better to use mysqli functions. but for this, edit the question and type the query, or simply put a die(mysql_error()) at the end of your query which is in $query. It will show your exact error.

share|improve this answer

i fugured it out when i was testing the function i commented out the original code on the main page but for some reason i had not comented out enough (it was a mix of php and html clearly the php had not been commented out properly) this must have been causing a clash of some kind as when i put the function above the code on my page the function worked and the long code below it did not

sorry for wasting your time guys

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.