premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
The '\\serverName' (note single quotes) would be correct, but I think you have to actually connect to that network drive. Look into fsockopen and those functions for more information on this.
-
[SOLVED] Maximum Commands Per Page. Is 52 Too Many?
premiso replied to Fluoresce's topic in PHP Coding Help
One other minor fix (edit time was up) $start = substr($row['make'], 0); Should be $start = substr($row['make'], 0, 1); Sorry about that. -
Not via session, it has to be sent via POST or GET to the php script. You can do this by using a form or looking into AJAX to send the request without a page reload.
-
[SOLVED] Maximum Commands Per Page. Is 52 Too Many?
premiso replied to Fluoresce's topic in PHP Coding Help
<?php $query = "SELECT make, url FROM tmake ORDER BY make"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); if(mysql_num_rows($result) > 0) { $last_start = "A"; while($row = mysql_fetch_assoc($result)) { $start = substr($row['make'], 0); if ($start != $last_start) { $last_start = $start; echo "<br /><b>" . $start . "</b><br />"; } $tResult = mysql_query("SELECT count(model) FROM models WHERE make = '{$row['make']}'"); $total = mysql_result($tResult, 0); echo "<a href=\"{$row['url']}\">{$row['make']}</a> ({$total})<br />"; } // end while }// end if else { echo "None"; } ?> That should get you what you want. The inner query can probably be compressed into 1 query if I wanted to take the time to do it. But this will be better than your original code by far. Note that the tResult query will need to be modified to fit your models table structure. EDIT: Added the "A" "B" to the top etc. -
http://snaps.php.net/
-
Use AND instead of OR in the implode function to limit that. If you typed in "chris" and someone has a name of "christopher" it would find it given the "LIKE" clause. I am not sure what your database consists of. To add dob and username simply follow the scheme I setup for the "name" and "interests" on the php side. The OR keyword in MySQL says, Either This or This or This, where as and would be his name is this AND interests have to be this AND dob has to be this.
-
Sorry, I had to do this Why use a list why not just do this: $string = urldecode("Good%20Afternoon%20CMJ"); $var = explode(" ", $string); $var = $var[2]; echo $var; Since he only needs the 3rd one anyways.
-
Yes, you do. <form action="search.php" method="post"> <br /> Enter Name:<br /> <input name="name" type="text" size="40"/> <br /> And Or Enter Interests:<Br /> <input name="interests" type="text" size="40"/> <br /> <input type="submit" name="submit" value="search"/> </form> Try that and see where it get's you. EDIT: A side note for why none of the other guy's solutions worked. Your form was passing "Friendsearch" and you were checking for "name" in your script. Since they are not the same, that is why your original did not work. It was always checking if name was = "" (or nothing). Since that was never being populated with data due to the inconsistencies of the names. Just remember $_POST['index'] must correspond directly with your form input field names, or else it will not work/return nothing.
-
Now on your form, if you have an input field for "interests" and "name" filling those out and posting should automatically populate the search field and return those limited results.
-
Simple fix. <?php session_start(); $b = $_SESSION["gatekeeper"]; $find['name'] = isset($_POST['name'])?$_POST['name']:null; $find['interests'] = isset($_POST['interests'])?$_POST['interests']:null; $search = array(); foreach ($find as $key => $val) { if (!is_null($val)) { $search[] = "`{$key}` LIKE '%{$val}%'"; } } if (count($search) > 0) $search = " WHERE " . implode(" OR ", $search); // modified here else $search = ""; // displays everything, change this if you do not want that functionality. $conn = mysql_connect("localhost", "ccheckley", "4aPRaJew"); mysql_select_db("ccheckley"); $result = mysql_query("SELECT * FROM users {$search}"); // and here if (mysql_num_rows($result) > 1) { while ($row = mysql_fetch_assoc($result)) { echo " name: {$row['name']} <br/>"; echo " username: {$row['username']} <br/>"; echo " birthday: {$row['birthday']} <br/>"; echo " interests: {$row['interests']} <br/>"; echo " <a href='addfriend.php?username={$row['username']}'>Make this user your friend</a>"; } }else { echo "The search parameters you provided returned no results."; } ?> Basically you left all search parameters empty. The above should return all rows in the table if no search parameters are provided.
-
[php}$to_date = date('Y-m-d h:i:s'); $before_date = "2009-02-13 17:00:00"; $sql = "SELECT * FROM tabl_name WHERE reg_date BETWEEN '{$before_date}' AND '{$to_date}'"; That should get you on the right track. You may want to look into strtotime if you want to dynamically do this.
-
Change this portion, it means there was an error in the SQL statement: $result = mysql_query("SELECT * FROM users WHERE {$search}") or DIE(mysql_error() . "<br /> Using search string {$search}"); And see what that tells ya. As for it returning rubbish, that is on you to filter out user input and verifying certain input etc. I have provided a rough example, not knowing how your code looks. Also change this since your DB column name should be "interests" $find['interests'] = isset($_POST['interests'])?$_POST['interests']:null;
-
How is the timestamp stored in the DB? As an INT as a mysql Date/Time do you store the time or just the date? Let us know how it is stored in the DB and we can help you.
-
There is, you just have to setup your code that way. The following is untested, but "should" work pending any errors on my part: <?php session_start(); $b = $_SESSION["gatekeeper"]; $find['name'] = isset($_POST['name'])?$_POST['name']:null; $find['interest'] = isset($_POST['interest'])?$_POST['interest']:null; $search = array(); foreach ($find as $key => $val) { if (!is_null($val)) { $search[] = "`{$key}` LIKE '%{$val}%'"; } } if (count($search) > 0) $search = implode(" OR ", $search); else $search = ""; // displays everything, change this if you do not want that functionality. $conn = mysql_connect("localhost", "ccheckley", "4aPRaJew"); mysql_select_db("ccheckley"); $result = mysql_query("SELECT * FROM users WHERE {$search}"); if (mysql_num_rows($result) > 1) { while ($row = mysql_fetch_assoc($result)) { echo " name: {$row['name']} <br/>"; echo " username: {$row['username']} <br/>"; echo " birthday: {$row['birthday']} <br/>"; echo " interests: {$row['interests']} <br/>"; echo " <a href='addfriend.php?username={$row['username']}'>Make this user your friend</a>"; } }else { echo "Unable to locate any username's whose name is like {$a}"; } ?> This uses isset implode array and foreach to determine and create the search string.
-
[SOLVED] How would you trim excess spaces inside a string?
premiso replied to limitphp's topic in PHP Coding Help
Underscores/dashes are fine. The periods are probably fine too, I was just stating an obvious point, file names contain periods then the extension, which most search engines can interpret as so and rank you lower. I would disallow the use of periods, but that is me. A username does not need periods, a "display name" can have periods/whatever it wants. It is better, if you ask me, to keep usernames simple and straight forward, Aplhanumeric. -
Well this thread has really gone to crap. Alright I think what you are looking for is the "like" keyword in MySQL <?php session_start(); $b = $_SESSION["gatekeeper"]; $a = $_POST["name"]; $conn = mysql_connect("localhost", "ccheckley", "4aPRaJew"); mysql_select_db("ccheckley"); $result = mysql_query("SELECT * FROM users WHERE name LIKE '%{$a}%'"); if (mysql_num_rows($result) > 1) { while ($row = mysql_fetch_assoc($result)) { echo " name: {$row['name']} <br/>"; echo " username: {$row['username']} <br/>"; echo " birthday: {$row['birthday']} <br/>"; echo " interests: {$row['interests']} <br/>"; echo " <a href='addfriend.php?username={$row['username']}'>Make this user your friend</a>"; } }else { echo "Unable to locate any username's whose name is like {$a}"; } // not needed mysql_close($conn); ?> Give that code a try and see what comes of it. As a side note for you to look at later on I would look into utilizing mysql_real_escape_string for preventing SQL Injections. See if this gives you the desired results.
-
echo "<table>"; for ($i=0;$i<10;$i++) { $color='black'; if (($i%2) == 0) $color = 'red'; echo '<tr bgcolor="' . $color . '"> <td>The</td> <td>Color</td> <td>Is ' . $color . '</td> </tr>'; } echo "</table>"; You are still failing to provide a specific example. Hence the generic code examples.
-
Copying data to database table question???
premiso replied to Redlightpacket's topic in PHP Coding Help
You wild use a MySQL insert and or Update statement...but you are pulling it from the DB...is it not already saved to a table? -
[SOLVED] How would you trim excess spaces inside a string?
premiso replied to limitphp's topic in PHP Coding Help
Periods I would suggest against as they usually distinguish a file. Underscores are fine. As far as a safe list, google "SEO best practices". To me a - is better than an _ but that is just my preference. -
You may find explode useful.
-
No clue, you failed to provide any section of code. I explained it for you as you asked. I am not psychic and cannot read minds (unfortunately).
-
Modulus the % operator determines if a number, $i divided by another number, 2 has a remainder. If that number returned is == 0 then the number of $i is divisible by 2 without a remainder. So if $i is one, one dived by two has a remainder of .5, thus that number is "odd" if $i is 4, 4 divided by two has no remainder, so that would return 0 hence the number is even. Look up on Modulus via Google for more information on it.
-
while ($row = mysql_fetch_assoc($result)) { echo " <b>Username:</b> {$row['friend']} </br> "; } A while loop is what you were after.
-
Never used the kit. You might be better off posting on a specific forum for that kit or even the kit's website if they have one. The chances of someone who has used the kit and has encountered this problem on this forum are slim.
-
If that was the case then your code is coded "wrong". You should not output anything before any header calls. To avoid this, I store all output into a string, instead of echoing/printing it. Then after all the processing I echo that string, this does safe processing time (1 echo vs many) and allows for you to use the header functions. What you have done is more of a band-aid to the actual problem. Figured I would just let you know that. If you want help fixing the actual problem, post the code here and I would be glad to guide you through fixing it to output properly.