-
You could use cookies if you prefer. Sessions are fairly simple to work with-- just be sure to keep session_start() at the top of every single page and then $_SESSION is an array you can use between pages for the duration of the stay.
As for which I was talking about, you can do both. Point to a single page as needed, and use variables in the URL to specify info; also use $_POST to confirm that data was sent and do different things based on that. Most of that is just based on layout.
Think about a complex forum (like this one*). Everything is run through the same index page and then various actions are performed, usually based on the URL variables but also based on submitted forms and things like whether the user is logged in, etc. The single script then parses everything and serves whatever content should be done by a variety of conditional (if) statements, functions and includes(), sometimes including up to hundreds of pages in a single "script".
(*vbulletin is in the minority of forum software, running several processes through different pages than index.php but it's all still going through the same setup in a complex way; it still follows the same basic principles.)
As always, if it works, then just keep it simple, but this is stuff to think about for the future.
-
I've never worked with cookies either. I'm not a php programmer. I can get things to work only when I have explicit examples to follow.
I would like to put the action code in the same file as the form but have no clue how to do it.
I'd like to try using sessions for the agent issue but these two lines seem to cancel each other out so it doesn't make sense to me...
Code:
<?php
$agent = array('DD'=>'Debbie','JV'=>'Joanne','HS'=>'House');
//immediately above the foreach loop, add this:
$agent = '';
-
Oh, yes, I forgot about the $agent variable. Just rename one to something else. They're for different purposes.
Call the new one $currentagent for example.
I understand it can be difficult. This type of situation is where you choose whether it's better to just get it working or to perfect it. Especially for a page that gets limited use (admin pages are a perfect example) I see no point in perfecting it, though as I said it's worth thinking about these ideas for later because you'll probably run into the same general ideas.
If you want to get an idea of a single page doing a lot, consider looking at some free forum software and how it's all setup. It's IMMENSELY complex, but you can get a feel for the whole layout and see some of the syntax for how it all relates.
Basically you use exactly the same tools you've been using, but just larger and larger code blocks and many more levels-- 1000s of lines code and sometimes a dozen tabs in (within ifs and loops, etc).
Of course this specific case wouldn't be anywhere near that complex, but it's the same idea and method-- just build up the same stuff you do know and you'll find you've made a very complex page.
-
And then you said...
Code:
//then replace this line:
if (isset($_POST['agent']) && $_POST['agent'] == $agentv)) {
//with:
if ($agent==$agentv) {...
but there is no line like that, only a line like this...
Code:
$selected = (isset($_POST['agent']) && $_POST['agent'] == $agentv)?' selected':'';
Is that the line you meant? And if so, I should replace it with what? I have to take what you say literally and do not know enough to recognize if you meant to say something else. I would really appreciate if you could please put the code in one chunk with everything the way you meant to say it. I would really like to get this working properly.
And this is not for the admin page for a website. It is for a custom app that will be used to run an art gallery. The invoices are piling up while they wait for me to design the CMS, clean up 30 years of data, and write the app. The pressure is killing me.
I am trying to simplify, not make things more complex. In that car rental app you helped me with, I put all the "write to database" modules in one little file no problem. I was just hoping to do the same thing here, but maybe it doesn't work with form actions.
I really appreciate your efforts to help me. God knows I need all the help I can get!
-
Sorry, I had accidentally cut and paste from the code that bluewalrus wrote "translating" my original code. Yes, that's the right line.
$selected = ($currentagent == $agentv)?' selected''';
(where $currentagent is that new variable I made...)
It's always a tradeoff whether you want to make things more complex, streamlined and in general "advanced". If it works, don't break it by trying to fix it.
Putting anything into a single page is very possible including form actions. Just output different pages based on what is going on.
The easiest way to get started with this is to comment your entire script and clean up the code as much as you can (tabs, extra lines between different sections) and maybe split it into different files to be included.
-
Can you please tell me what is wrong with this statement? Or if there is a better way to do it? Thanks.
This does work without the thousands separator...
Code:
<?php $result = mysql_query("SELECT COUNT(*) FROM client");?><b><?php echo mysql_result($result,0,0);?>
This doesn't work when I try to add a thousands separator...
Code:
<?php $result = mysql_query("SELECT COUNT(*) FROM client");?><b><?php echo mysql_result(number_format($result,0,0));?>
-
Isn't that just layered in the wrong order?
mysql_result() gets the data, THEN you want to format is using number_format().
So just do number_format(mysql_result(...))?
-
Brilliant.. that was it! Mahalo!! :)
-
Hey Daniel:
You're not going to believe this but I figured out how to get the drop-down to default to the last agent entered! It's no doubt a horrible adulteration of the php language but it works...
I had to change both forms to POST instead of GET, then I added this to the action file of the second form...
Code:
if($_POST['agent'] == 'DD'){
header("Location: /admin/php/client-history-add.php?agent=DD");
} elseif($_POST['agent'] == 'JV'){
header("Location: /admin/php/client-history-add.php?agent=JV");
} else {
header("Location: /admin/php/client-history-add.php?agent=HS");
}
Then I put this at the top of the form file...
Code:
<?php if(isset($_GET['agent']) && $_GET['agent'] == "DD"){ $ddsel = " selected";
} elseif(isset($_GET['agent']) && $_GET['agent'] == "JV"){ $jvsel = " selected";
} elseif(isset($_GET['agent']) && $_GET['agent'] == "HS"){ $hssel = " selected"; }
?>
And this in the form...
Code:
<select name="agent">
<option value="JV"<?php echo $jvsel;?>>Joanne</option>
<option value="DD"<?php echo $ddsel;?>>Debbie</option>
<option value="HS"<?php echo $hssel;?>>House</option>
</select></p>
And that's it! Works like a charm. It came to me while I was running. Feel free to tell me what's wrong about it. Thanks, e :)
-
That's a really simple way to do it, actually. Nothing's wrong with it. It's just not expandable/variable. If you do it in a way like I did before it was completely customizable and expandable to more names, etc. But for your purposes that's simpler.
And of course the main problem is that you must include that extra variable in every URL, so pay attention to that.