
jamesjmann
Members-
Posts
247 -
Joined
-
Last visited
Everything posted by jamesjmann
-
Highlighting Search Keywords In Search Results
jamesjmann replied to jamesjmann's topic in PHP Coding Help
There's absolutely no difference. The point of using a variable at all is so you can write code that does something to the contents of that variable. It does not matter if that variable gets set from a literal string assignment in some code to demonstrate how to do something or if that variable gets set by fetching a value from a database query. <?php //Display replies if ($count_4 > 0) { $keywords = str_replace(" ", "|", $string); while ($row_4 = mysql_fetch_array($result_4)) { $new_string = preg_replace("/($keywords)/i", "<b>$1</b>", $row_4["reply"]); echo $new_string; } } ?> Can you explain what the above code does? what's with the "|" character, and where did you get the random "i" in the pattern and the $1 variable? -
Highlighting Search Keywords In Search Results
jamesjmann replied to jamesjmann's topic in PHP Coding Help
Mine just makes the words bold too, but what is the difference between yours and mine? and don't forget, im using mysql to get data and storing it into variables, unlike you where your declaring a static variable. i think there's a huge difference between applying this method to a static variable, and applying it to a dynamic variable that runs through a loop. -
I have this so far, but all it does is hightlight ONE of the search keywords out of the item retrieved from the database... <?php //Display replies if ($count_4 > 0) { while ($row_4 = mysql_fetch_array($result_4)) { $keywords = explode (" ", $string); foreach ($keywords as $field => $value) { $new_row = $row_4["reply"]; $newest_row = preg_replace ("/$value/", "<strong>$value</strong>", "$new_row"); } echo $newest_row; } } ?> Basically, it goes through every item to be fetched; explodes the string they searched into an array (only if spaces were used), then goes through each individual topic and finds and replaces each keyword with the same keyword in bold. For some reason it only "bolds" one of the keywords out of the array. Anyone know how to fix this?
-
Which would you recommend I use? I personally would prefer doing it the classic if/else way...is there a difference?
-
I have one last question, though, because this is bugging the hell out of me and I won't rest in peace tonight if I don't ask. What's this line? <?php $user = ($find_members_online_ro["forum_rank"] == "Site Owner")?"<span style='color:#FF0000'>{$find_members_online_ro["username"]}</span>":$find_members_online_ro["username"]; ?> I've never seen a variable declared like this. $ = ()?: Is this a fancy, alternative way of declaring a variable?
-
I managed to combine everyones script with mine to form this: <?php $find_members_online_q = "SELECT username, forum_rank FROM fans WHERE status = 'Online'"; $find_members_online_r = mysql_query($find_members_online_q); $find_members_online_c = mysql_num_rows($find_members_online_r); echo "<span style='font-weight:bold'>" . $find_members_online_c . " members</span> are online<br><br>"; $tmp = array(); while ($find_members_online_ro = mysql_fetch_array($find_members_online_r)) { $user = ($find_members_online_ro["forum_rank"] == "Site Owner")?"<span style='color:#FF0000'>{$find_members_online_ro["username"]}</span>":$find_members_online_ro["username"]; $tmp[] = "<a href='../profile.php?action=view&username=" . $find_members_online_ro["username"] . "'>$user</a>"; } $last_element = array_pop ($tmp); echo implode(', ', $tmp); echo ", and " . $last_element; ?> This does PRECISELY what I need. Thanks for all the effort everyone, much appreciated =)
-
You know there is a manual for php, right? Having us explain a function to you which has clear documentation with examples and user comments is a useless activity. Now, if you were to have read the manual and still have questions, then by allmeans ask. http://us2.php.net/manual/en/function.implode.php Try this code <?php //Create and run query $query = "SELECT * FROM fans WHERE status = 'Online'"; $result = mysql_query($find_members_online_q); //Process results $memberAry = array(); $baseURL = "../profile.php?action=view&username="; $memberCount = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $style = ($row['forum_rank'] == 'Site Owner') ? " style='color: #FF0000'" :'' ; $urlUname = urlencode($row['username']); $memberAry[] = "<a href='{$baseURL}{$urlUname}'{$style}>{$row['username']}</a>"; } //Output results echo "<strong>{$memberCount} members</strong> are online<br><br>\n"; echo implode (", ", $memberAry); ?> I was incidentally reading about both explode and implode before I came across this problem today, actually, and I'm posting about it, because I didn't know you could use implode for this type of thing. I was fully aware what implode did before coming to this forum and posting about this, but the way in which it is used here confused me, hence why I asked. Still have a problem though if anyone can help. I want to put an "and" before the last name and after the last comma. how do i do that?
-
Here's the code right now. Sorry if it seems a it complicated to read. <?php $find_members_online_q = "SELECT * FROM fans WHERE status = 'Online'"; $find_members_online_r = mysql_query($find_members_online_q); $find_members_online_c = mysql_num_rows($find_members_online_r); echo "<strong>" . $find_members_online_c . " members</strong> are online<br><br>"; while ($find_members_online_ro = mysql_fetch_array($find_members_online_r)) { $tmp[] = $find_members_online_ro["username"]; } echo "<a href='../profile.php?action=view&username=" . implode (", ", $tmp) . "' "; if ($find_members_online_ro["forum_rank"] == "Site Owner") { echo "style='color: #FF0000'"; } echo ">" . implode (", ", $tmp) . "</a>"; ?> One thing about this script is it makes all of the names one big link, but I want each name to be its own link.
-
Okay, what you suggested works, but can you explain what's going on here? I'm not too familiar with implode and have no idea what the code does. I noticed the array $tmp gets carried outside of the while loop and the while loop constructs the array, but how is the comma getting excluded from the last name and how could i place an "and" in there?
-
I want to display member's names, each separated by a comma, but have no comma after the last one. I'm using mysql to store them. This is an example of what I have: <?php $query = "SELECT * FROM members"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo $row["username"] . ", "; } ?> What I want the above script to output is..."james, bob, dave, elisha, and maureen", but it only outputs, "james, bob, dave, elisha, maureen, " There's an extra comma and space after the last name with using the above script, so...how do I get that "and" in there and make sure there's no comma after the last name to be displayed? I've tried everything I can think of, but to no avail. Anyone?
-
Like using ajax to upload the photo, or in otherwords, getting javascript to transfer the photo to the php file so it can get read. hope that makes sense.
-
Is it at all possible to use ajax to upload photo data to a server? I'm very familiar with ajax, but I heard it was not possible and have not tried exchanging this type of data via ajax before.
-
your welcome, say hello from me to your god Lol, will do =p
-
OMG Thank you so much!
-
I created a javascript function that covers the entire screen with a semi transparent black png when a user clicks a button to pop up a dialog box. problem is, the png doesn't repeat to cover the entire web page. it covers the entire width of the page and the entire height of the computer screen, but when you scroll down, the png stops repeating. hope you guys know what im talking about but heres my css for the div that holds that transparent png. background-image: url(../images/template/faded-bg.png); background-repeat: repeat; top: 0px; left: 0px; position: absolute; display: none; width: 100%; height: 100%; background-attachment: fixed; background-attachment does nothing. i tried both fixed and scroll but no luck. anyone know how to fix this problem?
-
Hi, I'm trying to make a dynamic html table to contain the mysql data that is generated via php. I'm trying to display a user's friends in a table of two columns and however many rows, but can't seem to figure out what is needed to make this work. Here's my code as it stands: <?php //Begin mysql query $sql = "SELECT * FROM friends WHERE username = '{$_GET['username']}' AND status = 'Active' ORDER BY friends_with ASC"; $result = mysql_query($sql); $count = mysql_num_rows($result); $sql_2 = "SELECT * FROM friends WHERE friends_with = '{$_GET['username']}' AND status = 'Active' ORDER BY username ASC"; $result_2 = mysql_query($sql_2); $count_2 = mysql_num_rows($result_2); while ($row = mysql_fetch_array($result)) { echo $row["friendswith"] . "<br>"; } while ($row_2 = mysql_fetch_array($result_2)) { echo $row_2["username"] . "<br>"; } ?> The above simply outputs all records of a user's friends (their usernames) in alphabetical order. The question of how I'd generate a new row each time a certain amount of columns have been met, however, is beyond me. Anyone know of any helpful resources that may solve my problem? Thanks in advance =)
-
Hi, I'm wanting to toggle the opacity of the background everytime some clicks on the "control panel" button. It's initially hidden and if they click on it, it slowly fades in. If they click again, it slowly fades out; this was achieved using a simple fadeToggle. So far so good. Now, at the same time, I want the background (<body>) to slowly fadeTo an opacity of about say "0.5"; and then, of course, back to "1.0" if clicked again. Does anyone know of a good toggle function that can allow such a thing to occur? Here's my current JQuery code. Can someone please insert that toggle function in my current function where it needs to go? Thanks in advance! function slide_me() { $("#controlPanel").fadeToggle(500); <!--I'm assuming it would go here...?--> } $(document).ready(hide_panel); function hide_panel() { $("#controlPanel").hide(); } EDIT: Another thing, is as soon as the document loads (or is "ready"), the control panel div is not being hidden. No idea what the problem here is with that. Does anyone see anything wrong in my code?
-
I was wondering if its possible to add new elements to anarray i have called "$_SESSION['error']" like this: <?php $_SESSION["errors"][] = "string"; ?> Because i have a whole bunch of if statements that check my registration form and currently, if an error is found, i add a new element to that array like this: <?php $_SESSION["errors"]["var"] = "string"; ?> Then i echo the form again with this: <?php Foreach ($_SESSION["error"] as $object => $value) { echo $value; } ?> which basically just echos error messages...but the thing is is that i have a LOT of fields and its getting tiring having to give each error a unique name. So is it possible to add new elements to this array like that? Do the array elements automatically get id's?
-
You have a second parenthesis after the second strlen ("strlen((") I think you meant to put it after the second strlen ("strlen($review))"). In any case, its rather needless to enclose both strlen's in parenthesis. I would just write it as: <?php if (strlen($review) < 255 && strlen($review) > 30) { //blahblahblahblah } else { //blahblahblahblah } ?>
-
Haha wow. Shuda seen that one comin
-
Post the rest of ur script
-
I jusy forgot. Pika's right. U wanna use the strlen function, unless of course $review is an integer.
-
Echo $review to see if the variable is getting the string. Also print_r the post array to make sure the text areas value is getting registered. Thats a start...