Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





How To Assign Data In A Table Field To A Variable


what exactly do i do to only retrieve information from a table and assign it to a variable? I don't want to manipulate the data in any way, just display it on the page.




View Complete Forum Thread with Replies

Related Forum Messages:
Assign Variable From Database Field
Is there a way to assign a variable from a database field? I'm thinking along the lines of

$make = $row_rsList['make'];
$model = $row_rsList['model'];

then they'll switch out based on my SQL WHERE statement. This valid syntax?

View Replies !
Set Variable Name Use Field Name From Table
I have a query string that sets the value of Variables below:

if ($DB == "Departments") {
$tracking_id = $data22['tracking_id'];
$dept_name = $data22['dept_name'];}

simple and straight forward. Now I would like to set a loop that would set the variable name and value based on the field names in the table queried.

if ($DB == "Departments") {
$querystring = "Select * from ".$DB;
$result=mysql_query($querystring);
while(($field = mysql_fetch_field($result))) {
$field->name = $data22[$field->name];}}

can I set the variable name using the $field->name if so how? I have tried this code with no luck and no luck searching. This is a small example. I have queries with fifteen plus fields. This would also remove the need to modify this code if a field needs to be added to the table. And yes I have had to add fields to the tables.

View Replies !
Pulling Data From The Last Field Of A Table
What is the command to view the last result in a table using a DB query?

Table Example
TABLE PEOPLE
>ID
>NAME
>POINTS

one thing, it cant be ORDER BY id DESC

If at all possible it has to be
SELECT * FROM people WHERE name=jon && id=**last id**

**last id** = Last id where the name jon was found.

View Replies !
Inserting Data Into A Table With Auto Increment In One Field
i have a table with several fileds in and with the first one being an auto increment field. I want to know what my SQL query should be when inserting data. Here's my current one: Code:

$SQL = mysql_query("INSERT INTO $usertable2 VALUES('$subject', '$newstext', '$date', '$usrname')";

The auto increment field is the first in the table and is called 'postid'. can someone give me the correct query please? also do i need the first entry in the table to be a blank one with just the postid entered at one?

View Replies !
Can I Assign A Number To The Name Value In A Text Field?
I'm using a while loop to query products from a table to create an orderform. Works fine.
The products and descriptions "echo" on the page to create the orderform and a text field named "qty" for quantity ordered is written for each product in the table. Code:

View Replies !
Assign Table Value As A Session??
someone logs into my application - a login function runs from a pinc file.  What is suppose to happen is if the username and password match - it is suppose to assign a session to the username - which is being passed from form and to the first and last name which are in the table for the user.  Can I assign a session variable to value in a mysql table?  It does properly set the cookie I am assigning on the setCookie line but is is not setting any of the three sessions.  Here is the function I am using: Code:

View Replies !
Variable Data In Dynamic Table.
What I'm trying to do is list the values of an array into different table rows while alternating the color of the table rows. Simple enough right? It makes the table fine. Creates the proper ammount of rows. It even alternates color (yay!). The only thing that it doesn't do is list the values in the array. PHP Code:

View Replies !
Data From Table Based On Variable
Im making a website where users sign up to a club each user has a user_id and each club has a club_id. On the first page after logging in I want to be able to include a standard welcome message which will say something like "Welcome to $clubname".

Then once the admin signs in he then has the ability to edit the post and write some information on the club and save it.

However within the website there are lots of different clubs so I need the message that applies to a particular club to only be visible if the user is linked to the club.

My database has 3 tables, 1 for users, 1 for clubs and 1 for welcome.

View Replies !
How To Assign Which Table To LIMIT In From A JOIN?
I'm joining two tables "classrooms" and "students". 'Classrooms' has 7 school subjects and 'Students' has a list of students with their grades from the classrooms.

I'm trying to do a while loop pulling a list of all the classrooms and pull only 1 student with the highest grade displayed next to the classroom. I did a JOIN but it's displaying all the students on each class. Code:

View Replies !
Assign Value To Variable
Is there any way I can use a function to create a variable and assign
a value to it? I have a Perl script that returns some LDAP
information:

sn=Shore
givenname=Mike
logintime=20041008153445Z
logindisabled=FALSE

Instead of parsing this text and assigning the values, I was wondering
if a function exists where I can pass a variable name and a value, and
the variable would be created.

ie. somefunc("sn", "Shore")

Would create the variable $sn and assign the value "Shore" to it.

View Replies !
Assign To Variable
I am trying to take data from the database and assign it to a variable but i'm not sure how this is the code ive been trying

$sql = "SELECT Name FROM Names WHERE Name = 'Peter'";

while($row = @mysql_fetch_array($sql))
{
$var == $row['Name'];
}

View Replies !
Assign Javascript Variable To PHP Variable
i have select option on my website.When i choose select option  the value of selecet option which i get in the javascript want to assign to PHP variable .So that i can use that in the query.

View Replies !
How Can I Assign Output To A Variable?
I'm trying to send an email and would like to put the output of some of my script into the body of the email. Here's the part that needs to be executed: PHP Code:

View Replies !
Retrieve Data From Table With Multiple Returned Variable
I am trying to set up a function to recalculate prices for my products - (per product that is) The problem I am having is that I have a table that stores the prices for each client type (so one product can have multiple prices) so I need to be able to recalculate the price for each client. Code:

View Replies !
Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ???

eg.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<? if (db_num_rows($qid_p) == 0) { ?>
<li>No
<? } ?>
<? while ($prod = db_fetch_object($qid_p)) { ?>
<p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b>
<br><? pv($prod->description) ?>
<br>$<? pv($prod->price) ?>
<br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>]
<? } ?>

How to assign this code to a unique variable ???

View Replies !
Assign Function Output To Variable??
I've found some references to this topic at :
http://forums.devshed.com/showthrea...ion+to+variable
but it does not seem to be working for me.

here's a snippet...

<? PHP
function listPeople ($getArray)
{
foreach ( $getArray as $val )
{
echo "$val, ";
}
}

$foo = listPeople($splitDirector);
?>

The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.

View Replies !
Ways To Assign A Value To A Session Variable.
I am wandering which way to assign a value to a session variable
exist. Which of the following examples will work.

Example #1:
session_start();
session_register("ex");
$ex = 2.0;
Example #2:
In first.php:
session_start();
session_register("ex");
In second.php:
$ex = 2.0;
Example #3:
In first.php:
session_start();...

View Replies !
Get A Page Title And Assign It To A Variable
Is there a command or a procedure to get a page title and assign it to a php variable.


View Replies !
Assign Userid To A Session Variable
When a user logs into my system, i assign their userid to a session variable

[php]
$_SESSION['userid'] = $myrow[0];
[php]

and then a user logs out, i do the following

[php]
$_SESSION['userid'] = ''
session_write_close();
[php]

so, when a user clicks on a link to a page they should only see when logged in, i do the following test

[php]
if (isset($_SESSION['userid']))
{
header('Location: members.php3');
}

[php]

but the logout does not seem to work for some reason? userid still seems to be set after running the logout script, any ideas? am i doing something silly?

View Replies !
Assign Dynamic Dropdown To Variable?
Is it possible to assign a dynamic dropdown script to a $variable? Code:

View Replies !
Assign A New Value To A Variable Passed From An Html Form
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3.

if ($question3!="select days")
{
$question2=$question2+$question3;
}

This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.

View Replies !
Multi-Dimensional Arrays - Assign Variable
It's a simple question, but I'm just not
getting it.

I have two files:

<?php
$precinct = array (
array ( number=>2324,
centerlat=>-122.31705665588379,
centerlong=>47.710367959402525,
etc...

<?php
include ("precinctdata.php");
$filename = $_GET['id'];
$number = $precinct[filename-1][number];
etc...

I want to assign the value of "2324" to the variable $number. I've done
this with arrays that start with number=>1, 2, 3, etc., but not successfully
with specific values.

What am I missing?

View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use.

For example, right now I use a "workaround" technique from PHPBuilder:
$result=mysql_query("SELECT COUNT(*) FROM tablename");
list($numrows)=mysql_fetch_row($result);

Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable.

$result=mysql_query("SELECT COUNT(*) FROM tablename");
$numrows=mysteryfunction($result);

View Replies !
Assign Variable To A Block Of Html Code
Is it possible to assign variable to a block of html code?
Something like this :

$myblokvar = "<table width="487" border="0" cellspacing="0" cellpadding="0">
<tr> <td><table width="487" border="0" cellspacing="0" cellpadding="0">
<tr> <td><img src="images/bartitle_login.gif " alt="Login" width="475"...

View Replies !
Count The Number Of Matches And Assign A Variable For Each One
I've been trying to work out a problem but I'm having no luck. I have
field in my table for area and I need to count the number of matches
and assign a variable for each one.. this is what I have but it doesn't
work.. any ideas? Code:

View Replies !
XML: Assign A Variable To TransactionArray.Transaction.TransactionID Where User ID =?
I want to be able to find and assign a PHP variable to the Transaction ID where the UserID is a specified user though Ebays XML API. Code:

View Replies !
Store Date In A Date Field In My MYSQL Data Table
I have a form with a feild that when clicked on pops up a calendar which I can select a date I wnat to insert into the field. The date inserted displays "03 Apr, 2007". I want to store that date in a date field in my MYSQL data table, a field named "f_date" set to date type.

When I save the record the data field "f_date" displays "0000-00-00" which I take it the date input is not getting inserted to the table. My insert field code is PHP Code:

<input name="f_date"  type="text" class="bodytext" id="f_date" onclick='scwShow(this,this);' value="" size="15" />

View Replies !
Assign Variable Name As Variable
I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable.

For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop. Code:

View Replies !
Assign Variables To The Value Of The Post Variables Using The Field Names?
I’ve been using an older version of PHP up until recently. Using the older build I had 'register_long_arrays' on. However this depreciated some time ago and I want to start working with 'register_long_arrays' set to off.

My question is; if, for example you have a form with 25 fields is there a quick way assign variables to the value of the post variables using the field names? Code:

View Replies !
Pull Data From Mysql From A Varchar Field With Comma Seperated Data
I'm trying to pull data from mysql from a varchar field with comma seperated data, like: test, test, test, and so on. when I try to display the data i just get "array" in the input field. what i'm wondering is how can I show the data correctly? I'm a little lost here.

View Replies !
Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:

View Replies !
Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

View Replies !
Displaying Data From One Table But Ordering By Info From Another Table
I have two tables. One table (we'll call it 'table1') is set up like this:

email address userinfo
email@email1.com userdata1
email@email3.com userdata3
email@email2.com userdata2
etc... etc...

In the above table, the email addresses are in no particular order cause the row is created when someone adds their userinfo. Code:

View Replies !
Showing Data From A Table Based On Infos From Another Table!
i have 2 tables in my database : THREAD, and POST

THREAD's rows are: THREADID, TITLE + FORUMID + REPLYCOUNT + VIEWS
POST's rows are: THREADID, PAGETEXT and PARENTID

i'm a big php newbie... I want to display the LAST TWO messages (highest THREADID) of my forum number 99 (FORUMID=99).

I can probably do that, but the problem is that the text of the message is located in another table.. and it's getting too hard for my low-skilled brain lol

so basically I would like to check in "THREAD" for the highest THREADID where FORUMID=99, display the TITLE, REPLYCOUNT and VIEWS, and then check in POST for the same two THREADID's where PARENTID=0 (meaning it is the first message in the thread) and finally display the PAGETEXT !

Could anyone give me a PHP code that would display that?

View Replies !
Take Every Field From A Table
I take every field from a table (where there are many) and without referencing by name (using a loop) echo there name in a td followed by the contents? i think the foreach statement is what im looking for.

View Replies !
Table Id Field Int(6) What Does This Mean?
I have never really understood what the int(6) means. I know that is an integer, but does int(6) means I can have a table with a maximum 999999 records in it or has it got something to do with memory.

What happens after 999999 does the database revert back to 0 What about mediumint and bigint? If I wanted a database to have 999999999999 records would I need to use a mediumint(12)

View Replies !
Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

View Replies !
Getting Field Count From A Table.
I've searched through devshed but haven't found a reference to how to query a database for the contents of a table, then count the number of fields in that table. Can someone help?

Say, for instance, the call was FileName.php?table=Vendors

In FileName.php, once you'd done all the happy connect stuff,

$result = mysql_query("SELECT * FROM $table",$db);

how would you count the fields in the result, regardless of the number of rows?

I thought I could use mysql_fetch_row($result), then, with a single row selected count through the $myrow[] until they ceased to exist. Is this doable? It seems this would be fairly straightforward. Is there an easier/faster/better way? I'm still thumbing through my php/mysql tomb working on the problem but haven't found an obvious solution. Your thought are sincerely appreciated.

View Replies !
Get Max Value In MySQL Table Field
I have a 2-field table "pageref".

The fields are: "pagerefno" - which is index and primary key, and "url".

I need to find the max value in "pagerefno", so wrote the following code:

$query ="SELECT max(pagerefno) FROM pageref";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
echo row[0];

But this results in a blank screen. I'd be grateful for a steer, here.

View Replies !
Nonexistant Field In Table
I have a script that updates some mysql tables using input from a text file. The query that's giving me trouble is this one:

"UPDATE $table SET `$f` = '$v' WHERE id = '$new_id'"

where $f is the name of the field and $v is the value. The problem is, some of the information in the file is outdated, so some fields don't exist anymore. If I try to run the update with a field that doesn't exist, the script halts and I get an error.

Is there any way to have the script ignore this and just keep going?

View Replies !
How To Get A Field In The Last Row Of Mysql Table.
There is a certain field that I wish to get in the last row (it will always be in the last row, even if I add to the table) of my mysql table. How do I output this? I assumed that I would be using a LIMIT command and a DESCRIBE command, however I looked at mysql.com and couldn't find anything .

View Replies !
Select * From Table When Field Is Less Than 3
i think it simple but i want to select all db entries where a certain field is less than 3?

View Replies !
Mysql Table Field Name
would like to do a simple query that gets: mysql table field names and data. Is it possible to do this in one query? The result will be sent to a method that generates an html table with the mysql table field names as column description.

View Replies !
Using PHP In A MySql Table Field
I'm calling text from an mysql database which includes php. I have php echoing values in the database entry for concatenation purposes but when I write it to a page it just writes out the php code in the page source and the browser ignores it. Can I actually put php in a text field in mysql, do I have to format it or change the field type or how should I be approaching this?

database entry:
some text and <?php echo $value ?> more text
php calling the text from the database:
$SQL = "SELECT overview_content FROM   overview u
              WHERE  u.ov_id = '$ov_type' 
    " ;
   
$u = @mysql_query($SQL) or die("Couldn't execute query @mysql_query($SQL).");
   
$row =@mysql_fetch_array($u) ;
       
$the_overview = $row['overview_content'];
code is working fine and writing out the correct values, the php within the database entry is just being ignored.

View Replies !
Get Table/field Infomation
If a field in a table is set to be varchar(25), how do I find this information using a query? I wish to use the value as maxlength in a input field in a form.

View Replies !
Table Field Functions
Im using phpMyadmin to create my database tables and I have and ID, and USERNAME, and PASSWORD column, and when I add an actual username and password to the database it ask me what functions to set them as what should I put?

View Replies !
Updating An Table Field
I creating a new field in a table, and could use a little help in trying get the field populated correctly for each row. When the table is first created, the first row (id=1) has field called missions. And that field has inserted the following "1,2,3,4,5,6,7,8,9,10".

I simply went in order above 1 - 10, but the field will actually be populated with 1-20 in a random order, ie "6,12,19,3,8,1,16". Now what I'm trying to do, is for each row beneath (id's >=2) is to have the first number populate row 2, the second number populate row 3, and so on, down to the last row. After I understand how to correctly assign 1 value from row 1 into the remaining rows, I can then move onto the next step of my project.

View Replies !
Creating A New Table With A Variable Table Name
Is there a way to automatically create a table with a tablename that is taken from a field the user has previously entered (i.e. username). I have tried :

$sql ='CREATE TABLE $username (....)' and
$sql ='CREATE TABLE '$username' (....)'

but neither work. Any ideas??

View Replies !
Select From Table Where Field = String
How to select all lines containg a string (located in $pastmove) in the
moves column.

I tried several ways, for example:

$requete="SELECT moves, opening_id FROM suitemove where moves like
'%".$pastmove."%'";

but did not succeed;

View Replies !
How To Get Oracle Table Field Definition
from SQL*Plus, i use:

DESCRIBE MyTable

and I get this result (example):

View Replies !
Syntax For MIN And MAX Values Of A Field In A Table
I wish to assign a variable name to the MIN and MAX values of a field
in a table. The type is int(7).

I am extracting the field with many others with the following code
from a php call.

$ml_collect='SELECT * FROM ml_lopp LEFT JOIN scfmforening ON
(scfmforening.scfmnum=ml_lopp.scfmnum) LEFT JOIN ml_newtidplats ON
(ml_newtidplats.loppnum=ml_lopp.loppnum) ORDER BY date1,
ml_lopp.loppnum'

$ml_upg=mysql_query($ml_collect);

mysql_close();

The field is contained within the table ml_lopp and it is called
loppnum

I have been trying combinations of this to extract the min and max of
the field from the $ml_upg variable which includes all of the data to
be processed.

$lownum=mysql_result($ml_upg,MIN('loppnum'));
$hghnum=mysql_result($ml_upg,MAX('loppnum'));;

Which does not work.

View Replies !
How Do I Select The Last Field Of A Mysql Table ?
how do i select the last field of a mysql table ?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved