-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
well that code you kinda sorta posted you did if($_SESSION==1) it's supposed to be if($_SESSION["logged"]==1) I just assumed you were showing some pseudo-code to get your point across but if that's what you really did..
-
for some unknown reason I thought he meant scientific notation.
-
well I mean, I only use it when I have to but when I do I'm like "yay ternary ftw!" I even stand up and do the wave.
-
what? ternary is the bomb diggity yo I <3 ternary
-
http://www.php.net/sprintf
-
yes.
-
[SOLVED] Showing the selected option instead of its value
.josh replied to 86Stang's topic in PHP Coding Help
As Barand said: // example array to loop options $options = array('business' => 'Business Name', 'category' => 'Category', 'start_date' => 'Start Date'); echo "<select name='sort_option'>"; foreach ($options as $name => $value) { $selected = ($name == $sort_option)? "SELECTED" : ""; echo "<option value='$name' $selected>$value</option>"; } echo "</select>"; -
http://www.phpfreaks.com/tutorial/basic-pagination will show you the principle behind pagination.
-
As of right now you can a) Make a tutorial suggestion here, or b) Contribute in the forums and get recognized into a guru/recommended group, where you will be able to post your own tutorials.
-
<?php echo "<a href='test.php'>help</a>"; ?> php code needs to be wrapped in php tags and also your use of double quotes twice like that will confuse php so use single quotes inside the double quotes. Also the file extension (mime type) needs to be page.php or at least something recognized by your server to parse php scripts. And obviously you need to have the php parser installed. For longer pieces of html google HEREDOC
-
Look man, you asked for help on a very common thing, which suggests you didn't bother to even search. Then you flat out admit that you're trying to get someone to do it for you instead of search. I asked you to post code and errors. You posted some code yes, but you didn't tell us what's wrong. We aren't psychic. We don't know what your code is supposed to be doing in the context of the rest of your site, blahblahblah long story short, you need to help us in order for us to help you, and just posting something and saying "fix it" and acting like it's our "duty" to do it, is not our idea of you helping. At the end of the day, it's your problem, not ours, so getting an attitude about it only hurts you.
-
Haha don't mean to be mean but how about trying to figure out what's wrong with your script for hours on end and it's a simple parse error and you post it on some board like this and it's figured out in 2 seconds by someone
-
No I understood you, you want a dynamic dropdown. Show your code and what the error is. It may possibly be a problem with your php getting the data or it may be a problem with your javascript, idk, need more info.
-
well..yeah but it has to have a somepage.php extension and I am assuming that it's being run on a computer (server, whatever) that has server software like apache installed, as well as the php parser..
-
Okay well if you want just the numbers with a space between them just take out the comma <?php $lowestnum = 1; $highestnum = 200000; for($i=$lowestnum; $i<=$highestnum; $i++){ echo "$i "; } ?>
-
If you wanted the numbers with just spaces then take out the comma in "$i, " also were you wanting to somehow further format it as in make columns/rows?
-
You would do that with ajax. There are a million million billion examples of doing "dynamic dropdown" boxes. Google ftw.
-
mysql_result is only really useful in a circumstance where you want to loop through results but inside the loop, you want to "look ahead" to a row/col further down the result list. I guess this is useful, but honestly I have yet to have need of it.
-
yes it's the faster way. mysql already knows how many rows are there with count(*) and even if you specify a column, it would have to count the rows regardless, whether you do that or select * and get php to count it. The difference is that a) it's getting "counted" twice with num_rows and b) you're making sql select everything in your table and send it back to php when you don't need all that data. It's like if someone asks you how many pages are in a book and instead of telling them what the last page number is, you send them the whole book.. what I don't understand is why the count isn't working when you say the num_rows is..
-
look up regex in the manual there are a million and one examples of specifically checking email and domain formats in the comments.
-
well assuming that your table and column is named right and $id has the value you expect it to, it should work just fine. mysql_num_rows will work but you should be doing it in the query it's faster. And you don't have to assign an alias to it, nor do you have to specify a column.
-
[SOLVED] Populating template with mySQL database fields...?
.josh replied to lucretia23's topic in PHP Coding Help
Yes, that's exactly what that means. Select all the columns and all the rows of the table. So...you have a column named what, Id? And the data in that column is what, JobTitle+Dept? Like "DirectorFinance" would be in one of the cells of that table? <?php mysql_select_db($database_CompanyJobProfiles, $CompanyJobProfiles); // get the vars from the url $JobTitle = mysql_real_escape_string($_GET['JobTitle']); $Dept = mysql_real_escape_string($_GET['Finance']); $Id = $JobTitle . $Dept; $query_Recordset1 = "SELECT * FROM jobprofiledata WHERE Id = '$Id'"; $Recordset1 = mysql_query($query_Recordset1, $CompanyJobProfiles) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> Or am I understanding that wrong? Are you just wanting to select the row where jobtitle = director and dept = finance? <?php mysql_select_db($database_CompanyJobProfiles, $CompanyJobProfiles); // get the vars from the url $JobTitle = mysql_real_escape_string($_GET['JobTitle']); $Dept = mysql_real_escape_string($_GET['Finance']); $query_Recordset1 = "SELECT * FROM jobprofiledata WHERE JobTitle = '$JobTitle' AND Dept = '$Dept'"; $Recordset1 = mysql_query($query_Recordset1, $CompanyJobProfiles) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> -
[SOLVED] Populating template with mySQL database fields...?
.josh replied to lucretia23's topic in PHP Coding Help
Okay well it still sounds to me like what I told you before... from your code: <?php mysql_select_db($database_CompanyJobProfiles, $CompanyJobProfiles); $query_Recordset1 = "SELECT * FROM jobprofiledata"; $Recordset1 = mysql_query($query_Recordset1, $CompanyJobProfiles) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> Your code makes $row_Recordset1 and array of all the info in the row selected. Well, it takes the first row returned. Your query returns all of the columns in all of the rows of your table, and your mysql_fetch_assoc assigns the first row in the list to $row_Recordset1 as an array. Each element corresponds to the column so with your code, you can now use $row_Recordset1['columnnamehere'] wherever you want to in your script. You would just echo that out in the part you want it to show. Just replace 'columnnamehere' with the column name like $row_Recordset1['JobTitle']. Ideally you're going to want to reduce the results returned to only what you need, though. -
[SOLVED] Populating template with mySQL database fields...?
.josh replied to lucretia23's topic in PHP Coding Help
not really sure what you mean by "which recordset to get" do you mean how do you for instance echo out the results of your query? echo $_row_Recordset1['columnnamehere']; // put the column name in the quotes -
The way SQL injection attacks work is you finish off the query string by adding a ' and then starting a new query string or adding a new command or adding a condition that will always be true like 1=1 in order to alter the query string. SQL injection attacks pretty much rely on being able to add that quote in there, so it is virtually eliminated by simply doing mysql_real_escape_string($input) on your vars. If someone tries to input a quote it will be escaped like \' so that it will be taken literally.