|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Variable inside mysql_query
Hi there,
How I can use a varibale inside mysql_query? I'm passing a varibale $TableName to a function, and inside the function I make my query depend on the passed variable. $TableName = 'Users'; TestFunction($TableName); Function TestFunction($TableName) { $Query = " SELECT ID FROM $TableName "; $Result = mysql_query($Query) or die("Query Failed"); } How I can get this function works fine? |
|
#2
|
|||
|
|||
|
RE: Variable inside mysql_query
remove the spaces from the front and end:
$Query = "SELECT ID FROM $TableName"; |
|
#3
|
|||
|
|||
|
RE: Variable inside mysql_query
i am sure that spaces dont matter!
but i think that that code should work. what error do u get? do you even get an error? did u connect with mysql_connect()? did it success? do you know that mysql_query() doesn't return the value of the 'ID' field, (or any other field) but just a resource id, and u have to use that RID to get value of any field? (example from php man this is how u get field values from php! |
|
#4
|
|||
|
|||
|
RE: Variable inside mysql_query
To add:
If you want to fetch a row from the database, use the php function: mysql_fetch_row The way to do this is to assign a variable $row = mysql_fetch_row($query) then; echo $row[0]; It then treats the row as an array. To make it simpler, you can use mysql_fetch_array then use echo $row["name of field"]; Allowing you to call the fields by the same names they have in your db. |
|
#5
|
|||
|
|||
|
RE: Variable inside mysql_query
I am using the code from "Creating Dynamic Content with PHP and MySql" tutorial (see below):
And I get this error from the browser: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in...this line: while($myrow = mysql_fetch_array($result)) Code: |
|
#6
|
|||||
|
|||||
|
RE: Variable inside mysql_query
Anonymous try to post different questions in its own thread. Here try this
php Code:
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Variable inside mysql_query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|