You are here: Re: Best approach to run queries only when user chooses « All PHP « IT news, forums, messages
Re: Best approach to run queries only when user chooses

Posted by Jon on 10/25/05 17:21

Once you start to pass variables to more than just one page, I've found the
best method is to use session variables and start calling them from the
different pages. I try and limit the usage of sessions because it gets hard
to control where all of your data is located, but it's really handy if you
need to hold variables for multiple pages.

As far as the drop-down, I'm not quite sure what you're saying I guess. If
you want to populate a drop down list based on conditions, it's fairly easy
in PHP - Here's an outline of the process I would use:

<select name="nameSelect">
<?php
if/else conditions here
if($a==3){
echo "<option>Option from if condition</option>";
}else{
echo "<option>Option from else condition</option>";
}
?>

That's kind of the process I use - you are basically echoing the values in
the select list - if this were coming from a DB, you'd basically run this in
a loop of some sort likely using mysql_fetch_array
(while($row=mysql_fetch_array($queryResults)){
psuedocode from above here
}

Does that help?

"Ian Davies" <iandan.dav@virgin.net> wrote in message
news:1bn7f.443$sA4.156@newsfe2-win.ntli.net...
> Colin
>
>> I may be misunderstanding you - in which case I apologise for
>> patronising you - but it seems to me that you are not understanding how
>> the web works.
>
> You right there. I am new to web programming. I have a VB project that
> need
> to become web enabled and I am learning as I rewrite this project for the
> web. Thank you for all your information, it has been saved and will be
> added
> to my resources for future use.
>
> Another question. It seems that a variable can only be passed on to the
> next
> form. How can I pass it to a third form in the line? Would I have to 'leap
> frog' it from one hidden field to the next via a form's POST action or
> should I use sessions.
> Also if you know of a good link to a tutorial on the above and also on
> filtering values in a dropdown list based on the values in preceeding
> dropdown list I would be v grateful as most of my searches for such things
> lead usually to dead ends
>
> Thanks
> Ian
>
>>
>> Anything the user does is entirely on their client machine. They can
>> fill in forms and pick links (and possibly completely change what's on
>> the page they're looking at, if you've embedded suitable client-side
>> scripting in it- typically Javascript). But nothing can happen on the
>> server (such as changing the database) until they have requested a new
>> page, either by picking a link or submitting a form.
>> Of course, if it is to do anything other than simply sending HTML, that
>> page must be a CGI script. But it will not have any data from the user's
>> page unless the data has been sent back as CGI variables - either GET or
>> POST. Alternatively, in PHP they can have been preserved (on the server)
>> from when the previous page was processed, by using a _SESSION.
>>
>> If I understand correctly, what you really want is logically two
>> separate pages:
>>
>> page1.php:
>> // extract the data from SQL
>> // display it to the user
>> print "<a href='page2.php?arg1=$val1&arg2=$val2'>Confirm</a>";
>>
>> page2.php:
>> $sql = "INSERT INTO ... (arg1, arg2 ... ) VALUES ($_GET['arg1'],
>> $_GET['arg2'])";
>>
>> // display whatever you want the page to look like
>>
>> You can make them a single page if you want by (eg) making the link
>>
>> href='page1.php?confirm=yes&arg1=$val1&arg2=val2'
>>
>> and then starting your page with
>>
>> <?php
>> if (array_key_exists('confirm', $_GET) && $_GET['confirm'] == 'yes') {
>> // update database
>> } else {
>> // send request-confirmation page
>> }
>>
>> but you must still pass the data back from the client.
>>
>>
>> All the above assumes that it is practical and desirable to send the
>> data by GET. If you prefer POST (because there's too much of it, or
>> because you would rather it didn't appear in the URL, then you need to
>> use a form, even if there is nothing on it but a submit button:
>>
>> <form method='POST' action = 'page2.php'>
>> <input type='hidden' name='arg1' value='<?php echo $val1 ?>'>
>> <input type='hidden' name='arg2' value='<?php echo $val2 ?>'>
>> <submit name='confirm'>
>> </form>
>>
>> Then the variables will be available in the $_POST array in the next
>> page.
>>
>> Colin
>>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация