mySQL query problem

mySQL query problem
0

#1

Hi guys. Just wonder what’s wrong with this code:

$collect_codes = func_query(“SELECT value FROM dcodes”);


#2

That would depend on what programming language this is and what your mySQL database structure looks like and what kind of error message (if any) you are receiving.


#3

I use PHP 5. Database has table dcodes and row value.


#4

What is func_query?

Shouldn’t you be using

$result = mysql_query('SELECT value FROM dcodes');

Value should be a valid name of a column, and dcodes should be a valid name of a table.


#5

I used mysql_query, So now it runs but the new problem is that it doesn’t collect anything(but database has a value)


#6

Try this to see if there is anything at all in the table you are referring to:
$result = mysql_query("SELECT * FROM dcodes");

That will return the entire table. If your connection is established.
It will not have the field names (col headers) though.
Are you sure you have a column (field name) simply called value?

-WWC


#7

Yes, it has a column value with some numbers on the dcodes table


#8

I did this before with other tables and it was good and now nothing. Maybe I need to connect the database somehow again?


#9

That could be it.
Sometimes you need to logon to the server to access folders or databases.
If it is pulling nothing the connection could be the problem.

No errors?

You could try and connect to the data in another way, like scripting excel VBA, it will certainly throw an error if you can’t connect.

-WWC


#10

Please take note of the message here - http://php.net/manual/en/function.mysql-query.php
That is depcreated already and you need to use Myqli or PDO


#11

what’s wrong with this:

$result = mysql_query("SELECT * FROM dcodes");
	if ($result) {
    echo 'hi';
}else{

	echo 'bye';
}

I have table dcodes and it returns nothing and echoing ‘bye’.
What’s the problem?


#12

Because the condetion not completed


#13

What i mean is “deprecated” :smiley:, its just a typo. Its meant that it is already obsolete and wont be used anymore in the future php version.

Also that line, it will always be true, because its just evaluating whether the query you made is correct or not.
You need to use - mysql_fetch_row to count the number of rows or simply get the result via mysql-fetch-assoc.php

Enjoy coding.