0

Hello i am new at php.

$res=mysql_query('SELECT `order` FROM `competitions`');
    $row=mysql_fetch_row($res);

    if($row[order] == "1")
            {
            $res=mysql_query('SELECT `name`, `persp`, `teamp` FROM      `competitions_rank` WHERE `comp_id` = '.$_PARAMS[0].' ORDER BY `persp` DESC');
            }
    else
            {
            $res=mysql_query('SELECT `name`, `persp`, `teamp` FROM `competitions_rank` WHERE `comp_id` = '.$_PARAMS[0].' ORDER BY `teamp` DESC');
            }

In the database the possible values of the field is null, 1 or 2 .The code always enter in else statement. What i do wrong ? How i should check value in array returned by mysql_fetch_row ?

4 Answers 4

1

Well, first of all, you shouldn't use mysql_* functions. They're (unofficially) deprecated and not recommended for further use. Second, use $row["order"] and not $row[order] as there is no such thing as order in PHP.

Also, mysql_fetch_row returns the row as a numeric array, and not associative. if you insist on using mysql_, use mysql_fetch_assoc().

In addition to that, that entire statement should be inside a while loop because there could be more then one line that you are missing. If you want to make sure you only have 1 line, add LIMIT 1 to the end of your SQL query.

Sign up to request clarification or add additional context in comments.

2 Comments

This isnt working either. What is the alternative of mysql* functions ?
@Grigori Rangelov Like I said, you shouldn't use mysql_* consider rewriting your database coding style to PDO or at least to mysqli. It would help you with later projects as well!
1

this mysql_fetch_row function, Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.

so in your example you need to check it like :

if ($row[0] == "1")

Comments

1

I think problem is in mysql_fetch_row()... mysql_fetch_row — Get a result row as an enumerated array.

USE

mysql_fetch_array()

then

use $row['order']

Comments

0

I'm not quite sure what you're asking but could you update your sql query to

$res=mysql_query('SELECT `order` FROM `competitions ORDER BY order`');

Failing that you need to change

if($row[ 'order' ] == "1")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.