-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Community Answers
-
ginerjm's post in bind_result inside of a function was marked as the answer
Return the vars as arguments of the function with the & on each.
"function xyz(&$a, &$b)"
Call the function with "function ($a, $b)"
and then use $a & $b in your following code.
And - how does using an array of your two values cause duplication of code?
Anyway - your question is either how do I return the values or how do I echo the values? Which do you want to do?
-
ginerjm's post in Put values to text fields after submit was marked as the answer
They are local to the function. Pass them or make them global
-
ginerjm's post in Passing variables from function was marked as the answer
So? You write the array and save it as its own file. Then you include it in every script that needs to use it. The really smart thing would be to include the function there too and use an arg to feed it and accept a result when you call the function.
function GetGreeting($time) { $greetings = array( '0'=>'Good morning', '5'=>'You are late' '10'=>'you are real late' ); $str = (string) $time; return $greetings[$str]; } In your other scripts you do an "include 'getgreetings.php;'" and then call it with:
$greeting = GetGreeting($time);
and then output $greeting.
-
ginerjm's post in Integrate some code into another was marked as the answer
Show us what you mean. A lot of us do not click on random links....
-
ginerjm's post in Notice: Undefined offset: , CSV Fileupload PHP was marked as the answer
Your query is trying to insert 5 values into 4 columns.
-
ginerjm's post in Using <select><option>?</option></select> to display text. was marked as the answer
Try this instead
$select_tag = "<select onchange='reload(this.form)'>"; $select_tag .= "<option>test one</option>"; foreach ($data as $output) { $select_tag .= "<option>" . $output['header'] . "</option>"; } $select_tag .= "</select>"; Now - in your html area simply place the $select_tag var where you want this html to show up.
-
ginerjm's post in unlink first, then file_put_contents() is behaving weird was marked as the answer
Have you done a search of your script for another call to unlink?
-
ginerjm's post in Displaying Data to Specific User was marked as the answer
That would be "an extra column".
Now you need to revert this query back to a prepared one so you avoid un-filtered input being used.
-
ginerjm's post in md5 sum help was marked as the answer
There's probably more elegant ways but I would do a strpos on the string looking for a space.
Then I would grab the beginning part up to that position for the hash and then grab the part after that position for the filename.
Do a trim on each to get rid of any other chars.
$pos = strpos($string,' '); $value = trim(substr($string,0,$pos)); $filename = trim(substr($string,$pos));
-
ginerjm's post in Token Authentication - Cookie question was marked as the answer
???
You simply create a cookie FROM THE SERVER in the script that authenticates the access. Then wherever you need to check for a proper signon, in each script you simply check for the existence of that cookie. You can also store (perhaps) a value or two in the cookie if you need to know something about the user. DO NOT STORE any sensitive info in the cookie
-
ginerjm's post in Scope of calling exit was marked as the answer
Placing the exit() call following the function DOES make it as "readable as possible". Imagine you are looking at someone else's code where you see a call to a function and nothing after it and you wonder where the code is supposed to go next....
-
ginerjm's post in Left joins not being implemented correctly? was marked as the answer
Use different result names for your two different results. If you assign the name to both "opt_value"s, it's not going to look good coming out.
Ie, Tbla.opt_value as Opt_a, Tblb.opt_value as Opt_b
I didn't notice this in the code I myself posted for you.
-
ginerjm's post in Get "true" from multiple "if" was marked as the answer
You should do a little reading on the use of the if/else statement. Any php reference can help you understand how they are used. Especially the official PHP manual at php.net
-
ginerjm's post in rearrange info copied and change data pulled was marked as the answer
Step 1 - change the line that has $emp['city_name'] to something that has your group price value : $emp['group_price'] . I used 'group_price' since I don't know what you actual "group price" field is called.
As for the rest of the code you posted - why?
As for the whole thing in general - I can understand why the author is un-reachable. Hope you didn't pay too much.
-
ginerjm's post in Checking for available rows while navigating to next or previous element in the database was marked as the answer
If your row count is 0 then don't create the anchor tag.
-
ginerjm's post in Form Issue was marked as the answer
Try using an input element for your submit instead of the button one.
-
ginerjm's post in PHP script, selecting and inserting into mysql without duplicates was marked as the answer
Doing queries inside of loops is definitely to be avoided. Your situation does not necessitate breaking the rules here.
If you modify the structure of your prod. server's table to eliminate the AI setting on the PK, then you can simply do the query I suggested earlier since the keys from the phone server data will not conflict with the production server's db structure.
Get your Sql query writer to write your queries for you.
1 - Either keep track of (somehow) the id that was last added to your prod server. That or do a query on it to get the max value of id there.
2 - Write a query to insert into the prod server using the sub-query results that a query against the phone server where id > the last id inserted into the prod server (from #1)
That's all there is.
// first get the last id on the prod table $q1 = "select max(SESSIONID) as last_id from proddb.tablename"; $q1_ans = $pdo->query($q1); if (!$q1_ans) { echo "Could not get last inserted id from proddb"; exit(); } $row = $q1_ans->fetch(); $last_id = $row[0]; // now do the insert query $q2 = "INSERT into proddb.tablename (specify every column name in the order of the phone server's table structure here) SELECT * FROM phonedb.tablename WHERE phonedb.SESSIONID > $last_id"; $q2_ans = $pdo->query($q2); if (!$q2_ans) echo "Could not do insert query"; else echo "Insert query ran successfully";
Note: not exactly sure about the syntax of the #2 query. You may have to specify all of the phone server fidnames in the sub-query instead of the *.
Plus - I have never done queries that access separate servers before. Don't know how that is done but this is how it would work if using separate dbs on a single server. There may have to be some research into that. If it can't be done, then you could output the results of a query on the phone server to a table and use it in your #2 query after getting it to the prod server.
-
ginerjm's post in Piped email suddenly not working was marked as the answer
Well, while waiting for some input on this, I backed off all my edits on one of my 'offending' scripts and the problem went away. I have no idea what line(s) was/were the culprit. If anyone does have a good idea of what I may have done (hah!) I'd appreciate hearing about it. But - if you don't have a sure answer, then don't waste your time on my now-resolved problem.
-
ginerjm's post in 'Guess a number' - Help with hidden fields and arrays was marked as the answer
When you say it doesn't work, how do you know? Are you getting error messages? Is php error checking turned on (see my signature)?
-
ginerjm's post in special trim ? was marked as the answer
Solved.
While looping thru the number lists I was not properly recognizing the results. I was looking for a False result to indicate an error/bad value when I should have just checked the "corrected" value and replaced the original/bad one with it.
Now that I am doing that my process works.
Thanks for your interest!
-
ginerjm's post in Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in ... on line 42 was marked as the answer
The prepare will fail if the query is not formed properly. Any invalid column names, any missing parms ie, a mismatch in the number of values and fields. It's up to you to debug it. Remember that you cannot use a parm for the table name.
-
ginerjm's post in Implode array not working was marked as the answer
From another reader - properly stored data is never saved as an array. If you read up on RDBMS or 'relational databases' you will learn about how data should be stored.
In this case you will need to create a separate table that will have a key field related to the primary record (wherever you were planning on storing this array) and a field to store one item from this proposed array. This will create multiple records in the new table with all of the elements you wish to save. This may seem an odd way when one is so enamored with the array concept, but in the long run you will see the reasons. Of course no you have to understand how to do joins when you write a query, but that will come easily when you begin to read up on that!
-
ginerjm's post in Off topic but.... was marked as the answer
Hooray!! It seems that this problem has been resolved. Today I saw the 'black box' ads once again but they are different. They not have a single little icon in the right corner and now say 'Adchoices' like most of the time ads show. And they don't grab focus from other open windows.
-
ginerjm's post in PHP looping issue was marked as the answer
Have you attempted to do any reading/learning of php so that you might glean some knowledge of your own?
This is how it s/b written.
$select_var = "<select name='size' id='size'>"; while ($lrow = mssqlfetchassoc($tres)) { if ($row['tsdescription'] == $info['size']) $selected = 'selected'; else $selected = ''; $select_var .= "<option value='" . $lrow['ts_id'] . "' $selected>" . $row['description'] ."</option>"; } $select_var .= "</select>";
Always try and stay in php mode until you finally output your entire html doc. Here you build the necessary dropdown into a var. Down lower in your script where you assemble the bulk of you static and dynamic html, insert this var where it needs to be and your page will display it properly. Don't keep spitting out pieces of html and then doing some php and then spit out some html. It's confusing and hard to follow and even harder to maintain later on.