$code in Mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
joseazr1987
Forum Newbie
Posts: 10
Joined: Fri Aug 27, 2010 11:30 am

$code in Mysql

Post by joseazr1987 »

Hello, I turned out a doubt, want to get php variables in mysql and then call them. this example will say more or less what I mean

In MySql

tableVars
id value
1 $var1
2 $var2


in PHP

Code: Select all

<?php
mysql_connect(DB_HOST, DB_USER, DB_PASS);
mysql_select_db(DB_NAME);

$var1 = 'hello';
$var2 = 'world';


$sql = 'SELECT * FROM `tableVars`';
$res = mysql_query($sql);

echo 'results=';
while($row = mysql_fetch_assoc($res)){
echo $row['value'];
}


?>
i want this:
results = hello world
-------------------------------------------------
but my problems is when i call the rows and the results are $var1 $var2

:banghead:
:cry:

help me please...
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: $code in Mysql

Post by McInfo »

What is the purpose of storing a variable name in the database?

Anyway:

Code: Select all

$myVar = 'Hello';
$variableName = 'myVar';
echo $$variableName; // Hello
User avatar
joseazr1987
Forum Newbie
Posts: 10
Joined: Fri Aug 27, 2010 11:30 am

Re: $code in Mysql

Post by joseazr1987 »

The purpose for this is that I'll make a customizable form, and use variables to store the data and is not erased when they give you refresh, and i'm using $sessions[] to do that

look this is what I'm doing

this is in the database

Code: Select all

<form name="frmCotizar" method="post" action="">
<fieldset>
		<legend>Opciones Bebidas</legend>
		<input type="checkbox" name="jugo1" value="1" onClick="this.form.submit();" <?php echo $_SESSION['jugo1']; ?>/>jugo1
		<input type="checkbox" name="jugo2" value="1" onClick="this.form.submit();" <?php echo $_SESSION['jugo2']; ?> />jugo2
</fieldset>
</form>
and so called

Code: Select all

foreach ($ fields as $ field) (
echo $ field;
)
and seeing the source code so I get
<body>
name="frmCotizar" <form method="post" action="">
<fieldset>
<legend> Beverage Options </ legend>
<Input type = "checkbox" name = "jugo1" value = "1" onclick = "this.form.submit ();" <? Php echo $ _SESSION ['jugo1'];?> />
jugo1
<Input type = "checkbox" name = "jugo2" value = "1" onclick = "this.form.submit ();" <? Php echo $ _SESSION ['jugo2'];?> />
jugo2
</ Fieldset>
<form>
</ Body>

try to put it like this:

Code: Select all

'. $ _SESSION [' Jugo1 ']. "
but still does not work ..
Post Reply