-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
write string to 2 files at the same time, if statement is true
cyberRobot replied to devWhiz's topic in PHP Coding Help
Are those the only four tests? For example, will blue ever appear by itself? If it does, do you still want to print to blue.txt? Also, where does the string come from? Could the following happen: $string = "Blue, Green, Yellow.."; $string = "Yellow.."; -
How can I join a dropdown from another table?
cyberRobot replied to spacepoet's topic in PHP Coding Help
To get your drop-down menu selection to stick, you'll need to utilize the passed selection. In the code that generates the drop down, run a simple to test to see which one is selected add the selected attribute. For example: <?php ... echo "<select name='photo_category' size='1'>"; while( $row = mysql_fetch_array( $result ) ) { echo "<option value=\"".$row['category_id']."\""; if($photo_category == $row['category_id']) { echo ' selected="selected"'; } echo ">".$row['category_name']."</option>"; } echo "</select>"; ... ?> -
write string to 2 files at the same time, if statement is true
cyberRobot replied to devWhiz's topic in PHP Coding Help
You could use something like strpos() to figure out if the string contains the various colors. http://php.net/manual/en/function.strpos.php Then just create some if statements to write to the files: if(contains yellow) { write to yellow.txt } if(contains green) { write to green.txt } if(contains blue) { write to blue.txt } -
Good point, I was assuming that variable was populated by the program. If $searchfield contains data entered/selected by the user, make sure it's a valid choice.
-
Depending on how your database is setup and how the images (and video/sound files) are named, you could look into using the other database fields to display the image. For example, if your database table contains the following fields: id: 1, name: Car id: 2, name: Dog And you have images like: Car1.jpg Dog2.jpg You could display the images using both the "name" and "id" field. <?php ... while($row = mysql_fetch_array($result)) { echo "<img src='imagesFolder/$row[name]$row[id].jpg'>"; } ... ?>
-
If you're not doing so already, you should use the mysql_real_escape_string() on $search_term before querying the database. For more information, visit http://php.net/manual/en/function.mysql-real-escape-string.php
-
I think gristoi is on the right track. When calling your poptastic() function, the URL argument needs to be surrounded by quotes. So you could use something like: echo "<a href='javascript:poptastic(\"".$t."\");'><img src='$i1' height='100' width='100'/></a> "; Or: echo "<a href='javascript:poptastic(\"$t\");'><img src='$i1' height='100' width='100'/></a> "; Note that I removed the dots from the second code example.
-
That should work. Note that if you don't want to assign the modified string back to $_GET['name'], you could get rid of that part. $event = str_replace(".", " ", trim($_GET['name']));
-
You would replace $str with $_GET['name']: $_GET['name'] = str_replace(" ", ".", trim($_GET['name'])); Note that the above code currently replaces all space characters with a dot. But if I'm reading your original post correctly it sounds like you want to go the other way. So the code would be changed to: $_GET['name'] = str_replace(".", " ", trim($_GET['name']));
-
Is this for a WordPress website? If so, it looks like you can use the posts_nav_link() function to replace the next/previous post links with images. For more information, visit the Codex: http://codex.wordpress.org/Function_Reference/posts_nav_link
-
Based on the code provided, the if test is only going to execute once. If you want it to execute every time the while loops, you'll need to modify the code: <?php $count = 0; while ($row = mysql_fetch_assoc($Ships4)){ if ($count < $row_dclasscorella['Dclass4_totla']){ ... } } ?>
-
First, you're missing the end curly bracket in the JavaScript: <script type="text/javascript"> function showfield(activeDropDown) { ... } </script> Also, the onchange attribute will never get activated if the drop-down doesn't contain more than just the "Other..." option. You'll need to add more options to the School drop-down for the code to work. Before I get in trouble, it turns out that I didn't write the code in the above post. I was just correcting code written by the OP.
-
If you don't want to use jQuery, I've posted JavaScript code to a similar request here: http://www.phpfreaks.com/forums/index.php?topic=331574.msg1560437#msg1560437
-
Uh oh, if you start using jQuery, you might need to change your signature.
-
If I understand the issue correctly, it sounds like you're having problems with losing data in the second form; the one that displays the drop-down menu. If that's the case, you need to create hidden variables for whatever you want to pass through the form. For example: <input type="hidden" name="initialy" value="<?php echo $_POST['initialy']; ?>" /> Also, I would strongly recommend that you avoid using $_SERVER['PHP_SELF'] in your form action attribute. It's very easy to hack PHP_SELF when it's used in the action attribute, in links, or when it's displayed on screen. http://www.mc2design.com/blog/php_self-safe-alternatives
-
I'm sure there's a more efficient way, but you could get the extension by exploding the filename with the dot '.' <?php $file_parts = explode('.', $image); $temp = count($file_parts) - 1; $ext = $file_parts[$temp]; ?> Note there are some security issues to work on before going live. First you want to look into dealing with visitors who pretend to upload an image, but are actually uploading something like a PHP script and naming it "image.php.jpg" or "ScriptToDoSomethingBad.php". You'll also want to use mysql_real_escape_string() before saving the image name (and other information) to the database. Otherwise someone could modify/access you're database using SQL injections. http://php.net/manual/en/function.mysql-real-escape-string.php
-
Instead of potentially creating hundreds of PHP files that essentially do the same thing, wouldn't it be better to store all the picture references in a database? Then just use templates/pictures.php page to display them all based on a id. That way if the initial template ever changes, you would only need to modify one file.
-
Note that if you want the named anchor reference (#asd) to work, you'll need to add a named anchor near the <div> tag. <div id="asd"><a name="asd"></a> Hi there </div> If you add the named anchor it will jump to the newly shown content. If you don't want the page to jump to the new content the #asd isn't needed. You could just have the href attribute set to "123.html".
-
Error message passed through url not displayed correct
cyberRobot replied to drayarms's topic in PHP Coding Help
As xyph said, you would explode the string based on whatever's between the different error messages. Of course, if you're using the space character you should consider changing it to something else. Preferable something that's not commonly used in the error messages such as the straight bar "|". You could also use multiple characters such as ":|:". -
It sounds like you're trying to hide content so that visitors won't see it until they click a link. If that's correct, you'll need to use something like JavaScript. The following tutorial may help: http://www.cssnewbie.com/showhide-content-css-javascript/ On the other hand, if you're just looking to jump to the text after a link is clicked, you could look into named anchors: http://www.google.com/search?q=html+named+anchors
-
Error message passed through url not displayed correct
cyberRobot replied to drayarms's topic in PHP Coding Help
Isn't it because you're exploding the error string based on the space character? <?php $errors = explode(" ", $errors_string); ?> -
It seems like the logic behind the function should be modified. Instead of calling the function again to test the data you just read, why not test the data right away? Maybe switch it to: <?php function findEndTag($file, $line, $consolidatedLine) { $fileContent = file($file); foreach ($fileContent as $i => $lineArray) { if ($lineArray == $line) { $consolidatedLine = $consolidatedLine." ".$fileContent[$i+1]; $endTagFound = strstr($consolidatedLine,"/>"); if (!$endTagFound) { return (findEndTag($file, $fileContent[$i+1], $consolidatedLine)); } else { return $consolidatedLine; } } } } ?>
-
What does your code look like so far?
-
What do you mean by being able to access their account? Do they just see the page as if logged in or are they able to interact and do stuff with their account?
-
You could do something like: ... <select name="satisfied"> <option value="yes"<?php if($_POST['satisfied'] == 'yes') { echo ' selected="selected"'; } ?>> yes </option> <option value="no"<?php if($_POST['satisfied'] == 'no') { echo ' selected="selected"'; } ?>> no </option> </select> ... Also, you should avoid using $_SERVER['PHP_SELF'] in forms for security reasons. For more info, see: http://www.mc2design.com/blog/php_self-safe-alternatives