![]() |
plz help me here
hi
im trying to add best rated articles so i made this code PHP Code:
well it douesnt give any error just blank |
Ahh, the joys of debugging :) My first steps in this situation would be to do some basic checks to make sure the queries are running correctly.
For example, try putting: PHP Code:
PHP Code:
Performing these debugging steps should give you a clue as to where the problem lies :-) Alan. |
when i added var_dump the result is =>
array(2) { [0]=> string(1) "5" ["rate"]=> string(1) "5" } and when i add PHP Code:
Code:
bool(false) |
On the fourth line you are trying to get the value of
$mas['tuto_id'], but in your SQL query you only ask for the rate and no other columns. Therefore, tuto_id will not be available to use! The same problem exists for the query assigned to $web2 since no valid ID number is available.It is good practice to add in some checks into your scripts so that you can recognise errors or problems. You should always check to see whether MySQL encountered any error when processing a query ( mysql_query returns FALSE on error). Also you should check to see if the returned resuls are what you were looking for. For example, if no rows were returned you should output a message saying that nothing was returned, rather than just outputting nothing. |
Edit: Dam my slow typing - Salathe beat me to it :-D
Ok, so that means that $mas2 = false - when in reality, you where expecting it to contain an array (the rows from your query). As such, it's probably a good guess that your query: PHP Code:
If you take another look at your first var_dump() results, you will see that your query is only returning ['rate'] - which in this case equals 5. As such, $mas['tuto_id'] doesn't exist as your query doesn't return it. I would recommend changing your first query so that it fetches tuto_id as well. This should resolve your problem. Just remember in future, if in doubt - stick var_dump() statements all over your code until you track down the problem :-D Alan. |
thanks guys so i changed the query and make it like this
PHP Code:
Code:
array(2) { [0]=> string(2) "29" ["rate"]=> string(2) "29" } |
Your new query is now selecting the tuto_id that has the highest number - max(tuto_id) - then assigning it to a variable called 'rate'.
What are you actually trying to retrieve from your table? Am I right in guessing that you want to get the 'tuto_id' for the row that has the highest 'rate' ? Alan. |
yeah im trying to retrieve the highest number
and in the table tuto |
In that case, I would use a query like the following:
PHP Code:
Note: No-one has ever mistaken me for an SQL expert so I don't know if my query above is the "right" way to do it, but if it's wrong I'm sure someone else here can improve it :-D Alan. |
i cant use ur quesry so i edit it like that
$web = "SELECT tuto_id, rate FROM rate ORDER BY rate DESC LIMIT 1"; bcz tuto_id and rate are in table rate not on table tuto :s but still no results |
thanks now it works the problem was stupid sorry just from the database lol
but it just give 1 result i edit the query to be "LIMIT 4" and i want to show 4 results but just give 1 :s |
Edit: Didn't see the post above
Yes, just change the "LIMIT 1" to "LIMIT 4" if you want it to return the 4 rows with the highest rating :-) Don't forget that when you have changed the query, you will need to put your while() loop back in to loop through them Alan. |
i did it here is the code
PHP Code:
|
The new problem is because your second query only fetches 1 row.
I've adjusted your code so that it should read multiple rows using the SQL IN() function. PHP Code:
Alan |
it gives an error
PHP Code:
|
Then you need to do some debugging to find out where the problem is. For example, it looks like I mistyped something in the second query, so put an " or die(mysql_error())" after your mysql_query() and that should give us an error message.
You can then use this error message to track down the problem. Alan. |
| All times are GMT. The time now is 07:30 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0