Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

I guess there is a way to make a function out of this but ..

 
   Database Forums (Home) -> PHP RSS
Next:  SQL re-parsing on query executed against a remote..  
Author Message
none

External


Since: Oct 14, 2005
Posts: 2



(Msg. 1) Posted: Sat Oct 15, 2005 9:55 am
Post subject: I guess there is a way to make a function out of this but i
Archived from groups: alt>comp>lang>php (more info?)

As i said... I have several calls to the same "action" which i guess
could be resolved as a function: but i'm learning and i have no idea how
to do that.

I post the code, extremely boring i suppose. It's in italian, but it
shouldnt make such a difference, right?

The idea is that of making a form where the select options are taken
straight out of a mysql table, actually, a single column.

<?php

$database=****;

$link = mysql_connect('localhost', '***', '**********'); # connette a
mysql con user e pass
if (!$link) {
die('Could not connect: ' . mysql_error());
}

@mysql_select_db($database) or die( "Unable to select database"); #
connette al database indicato nella var database



# qui comincia il form coi vari select per i vantaggi etc...

<form action="pagina3.php" method="post">
<select name="vantaggi1">
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select van from vantaggi";
$res=mysql_query($query);
for ($i=0;$i<19;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>

<select name="vantaggi2">
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select van from vantaggi";
$res=mysql_query($query);
for ($i=0;$i<19;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>

<select name="vantaggi3">
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select van from vantaggi";
$res=mysql_query($query);
for ($i=0;$i<19;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>

# qui iniziano gli svantaggi

<br>
<select name="svantaggi1">
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select svan from svantaggi";
$res=mysql_query($query);
for ($i=0;$i<24;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>

<select name="svantaggi"2>
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select svan from svantaggi";
$res=mysql_query($query);
for ($i=0;$i<24;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>
<select name="svantaggi"3>
<option value="NULL" selected="selected">niente<br>
<?php

$i=0;
$query="select svan from svantaggi";
$res=mysql_query($query);
for ($i=0;$i<24;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
?>
</select>

# qui iniziano le abilità speciali

<br>
<select name="abspec1">
<option value="NULL" selected="selected" >niente<br>
<?php

$i=0;
$query="select abspec from abspec";
$res=mysql_query($query);
for ($i=0;$i<11;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}

?>
</select>

<select name="abspec2">
<option value="NULL" selected="selected" >niente<br>
<?php

$i=0;
$query="select abspec from abspec";
$res=mysql_query($query);
for ($i=0;$i<11;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}

?>
</select>

<select name="abspec3">
<option value="NULL" selected="selected" >niente<br>
<?php

$i=0;
$query="select abspec from abspec";
$res=mysql_query($query);
for ($i=0;$i<11;$i++){
$val=mysql_result($res,$i);
echo "<option value='$val'>$val";
}
mysql_close($link);
?>
</select>

<input type="submit" value="spara">
</form>

 >> Stay informed about: I guess there is a way to make a function out of this but .. 
Back to top
Login to vote
Tyrone Slothrop

External


Since: Dec 24, 2003
Posts: 47



(Msg. 2) Posted: Sat Oct 15, 2005 9:55 am
Post subject: Re: I guess there is a way to make a function out of this bu [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sat, 15 Oct 2005 14:49:47 +0200, none wrote:

>As i said... I have several calls to the same "action" which i guess
>could be resolved as a function: but i'm learning and i have no idea how
>to do that.
>
>I post the code, extremely boring i suppose. It's in italian, but it
>shouldnt make such a difference, right?
>
>The idea is that of making a form where the select options are taken
>straight out of a mysql table, actually, a single column.
>

You can do something like this:

function options ($table, $field) {
$qy = "SELECT $field FROM $table";
$rs = mysql_query ($qy) or die (mysql_error());
while ($r = mysql_fetch_array($rs)) { ?>
<option value="<?=$r[0]?>">$r[0]?></option>
?> }
}

This way you can just pass the field and table to the function and
display the results for all of your options.

 >> Stay informed about: I guess there is a way to make a function out of this but .. 
Back to top
Login to vote
none

External


Since: Oct 14, 2005
Posts: 2



(Msg. 3) Posted: Sat Oct 15, 2005 2:55 pm
Post subject: Re: I guess there is a way to make a function out of this bu [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for the answer, i'll give it a try

>
> You can do something like this:
>
> function options ($table, $field) {
> $qy = "SELECT $field FROM $table";
> $rs = mysql_query ($qy) or die (mysql_error());
> while ($r = mysql_fetch_array($rs)) { ?>
> <option value="<?=$r[0]?>">$r[0]?></option>
> ?> }
> }
>
> This way you can just pass the field and table to the function and
> display the results for all of your options.
>
 >> Stay informed about: I guess there is a way to make a function out of this but .. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
error while doing 'make' in php-5.2.1 - I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following errors..Not able to proceed further.(./configure went smooth). I...

How to make URL cloaking - Hi Everybody, I have a small question about URL cloaking, am working on an idea of creating URL cloaking system, this is that my users can get cloaked URLs for their long URLs in other words, if you have URL like this:..

Make the code be illegible - Hi, I would like to make a script in which there would be some google ads. The problem is if the PHP code source is available people will be able to delete the google ads part of the script... How can I make the code be illegible without using Ioncube....

Make the code be illegible - Hi, I would like to make a script in which there would be some google ads. The problem is if the PHP code source is available people will be able to delete the google ads part of the script... How can I make the code be illegible without using Ioncube....

trying to make characters safe for my RSS feed - Whenever users write a post in Microsoft Word and then post it to their weblogs using my PHP software, their RSS feed ends up being corrupted with garbage characters which violate the well-formedness of their XML and therefore cause their newsreaders to...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]