Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. I would suggest reading up on programming basics - the language is not important. Once you understand loops, functions, conditions, etc. then it is just a matter of learning the syntax of whatever language you are working in. So, if you are confronted with new code that you do not understand, you just need to read the manual - PHP has an excellent one with descriptions and examples at php.net. So, when you come to a command in the tutorial you do not understand read the manual for that command. It will be slow going at first, but as you master each command it becomes easier over time.
  2. Not really enough information really. I am assuming that the playlist that the user creates only contains track IDs and that is why you have to do a database query to get the track path? I did something similar before, but in a very different process. For my application, I did not want the user's to be able to access the music files directly. So, in my application I allowed the user to create "playlists" via a webpage. Those playlists were just database records. Then, when a user selected a link to play a playlist I would do a single query to the database to get the tracklist for the playlist (all I would get were the track IDs from the database). I would use the results of that query to build an actual flat-file playlist that could be consumed with the user's default media player. I would never actually write the file to disk - I would just use the appropriate headers to send the file to the user. Also, the actual playlist file would contain links such as www.mysite.com/playfile.php?id=23 www.mysite.com/playfile.php?id=187 www.mysite.com/playfile.php?id=93 The user's media player would make a request to the URLs above and that page would do a query to get the mp3 location and, using the appropriate headers, send the file to the user. I never had a problem with performance because I never had a ton of usage, plus when a user selected to play a playlist they would only be doing a database request once every 3-5 minutes.
  3. The wording of your request is a little confusing. I don't know what it means to hyperlink Javascript to an image. I fyou are saying you want a Javascript function to run when the user clicks an image, then just add an onclick event to the image. Based upon the button example in the code above I guess it would look something like this: onClick="popUp('<?php bloginfo('url');?>/my-account/shoppers-live-help-chat-system');"
  4. WIAT A MINUTE! You are testing the value of $integer and integer is set using $integer = $line_of_text[4]; But you don't set $line_of_text until AFTER you test $integer. So, $integer would have a null value when the IF condition is run. And, it just so happens that the IF condition will return true with a null value. Change to this: $file_handle = fopen("http://urlhere.com", "r"); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); $integer = $line_of_text[4]; if ($integer>=0.000) { $plusminus = '+'; $arrow = 'uparrow.png'; } else { $plusminus = '-'; $arrow = 'downarrow.png'; } }
  5. There HAS to be something wrong with the variable $integer. I did a quick testing using your IF conditional above and all of the following values produced a negative result, as expected: -0.005 - float '-0.005' - string (string)' -0.005 ' - string with spaces and tab character Also, not that it makes a difference, but why are you using 0.000 for the conditional test? Just use "0"
  6. Well, this appears to be your query for getting the records per page: $product_line_count = $product->db->get_row("SELECT COUNT(1) as `count` FROM `product_lines` WHERE `id_catp` = '".$_GET['id_catp']."' AND `id_cat` = '".$_GET['id_cat']."' AND `id_subcat` = '".$_GET['id_subcat']."'"); There are several items in the WHERE clause. Any chance some of those values are affecting the count? TIP: Create your querys as string variables so you can echo them to the page for debugging. At the very least it makes your code more readable. $query = "SELECT COUNT(1) as `count` FROM `product_lines` WHERE `id_catp` = '{$_GET['id_catp']}' AND `id_cat` = '{$_GET['id_cat']}' AND `id_subcat` = '{$_GET['id_subcat']}'"; $product_line_count = $product->db->get_row($query); Another possible issue: There are three different "counts": $product_line_count, $product_count & $total_itmes_count. It is unclear what the logic is behind these, but it seems $total_items_count is used in the calculation of $new_pages, which is used to display the pages. There is a function used to do that calculation [get_product_pages_parse()], so the problem could be in that function. The code do create teh actual page links is very confusing. There is a loop of $k from 1 to 3. In that loop you do a loop of $new_pages['split'][$k] to create the page links. That leads me to beloeve that the function get_product_pages_parse() is returning the total pages NOT in a single value but in three different array indexes. WTF??? Someone like arrays way too much and the code is way overcomplicated. For example, this: if($new_pages['split']['current_page_no']['section']==$k AND $new_pages['split']['current_page_no']['id']==$page_id) { echo ' <li><a href="'.$server_data['webroot'].'/products'.$page_link.'" class="page-active">'.$page_id.'</a></li> '; } else { echo ' <li><a href="'.$server_data['webroot'].'/products'.$page_link.'">'.$page_id.'</a></li> '; } // end ELSE Could be rewritten as this: $current = $new_pages['split']['current_page_no']; $li_class = ($current['section']==$k AND $current['id']==$page_id) ? ' class="page-active"' : ''; echo "<li><a href=\"{$server_data['webroot']}/products{$page_link}\"{$li_class}>{$page_id}</a></li>";
  7. You need to use the MySQL UNION command to merge the tables into one contiguous table. However, you can only do that if the tables have the EXACT same columns in the EXACT same order. If they are exactly the same, then look at this tutorial: http://www.tizag.com/sqlTutorial/sqlunion.php If they are not exactly the same (but the fields have the same format) you could try doing a UNION by only selecting the identical fields like this: SELECT article as name, time FROM articles UNION SELECT comment as name, time FROM comments
  8. That is a poorly designed database structure. You should have a separate table for the product names and then just reference the product ID in this table. WOuld make this much, much easier. But, using the structure you have, this should work (not tested so there may be some minor errors) <?php $query ="SELECT userid, product, SUM(qty) as qty FROM table1 GROUP BY userid, product ORDER BY userid, product"; $result = mysql_query($query); $products = array(); $userData = array(); while ($data = mysql_fetch_object($result)) { //Add product to array if not already exist if (!in_array($data->product, $products)) { $products[] = $data->product; } //Add user data to array if (!isset($userData[$data->userid])) { $userData[$data->userid] = array(); } $userData[$data->userid][$data->product] = $data->qty; } //Create table echo "<table>\n"; //Create headers echo "<th></th>\n"; foreach ($products as $product) { echo "<th>$product</th>\n"; } //Write user data foreach($userData as $userID => $data) { echo "<tr>\n"; echo "<td>$userID</td>\n"; foreach ($products as $product) { echo "<td>$data[$product]</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; ?>
  9. I think it would be better just to use an array of search/replace values instead of using multiple preg_replace() functions. Plus the function above didn't work for me. I have tested the following and it appears to work as you requested - although it may not be the most efficient $search = array( "/(<span style=\")(.*?)font-weight: bold;(.*?)(\">)(.*?)(<\/span>)/i", "/(<span style=\")(.*?)font-style: italic;(.*?)(\">)(.*?)(<\/span>)/i", "/(<span style=\")(.*?)text-decoration: underline;(.*?)(\">)(.*?)(<\/span>)/i", "/(<span style=\")(.*?) {2,}(.*?)(\">)/i", //remove duplicate spaces "/(<span style=\")( ){0,1}(\">)(.*?)(<\/span>)/i" //remove empty span tags ); $replace = array( "<b>$1$2$3$4$5$6</b>", "<i>$1$2$3$4$5$6</i>", "<u>$1$2$3$4$5$6</u>", "$1$2 $3$4", "$4" ); $str = 'please <span style="font-weight: bold; font-style: italic; text-decoration: underline;">replace me</span> then carry on here and <br><span style="font-weight: bold; font-style: italic;">replace me2</span> then carry on and <span style="text-decoration: underline;">replace me 3</span> then carry on and <span style="font-weight: bold;">replace me 4</span><br>'; $str = preg_replace($search, $replace, $str); echo $str; Output please <b><i><u>replace me</u></i></b> then carry on here and <br><b><i>replace me2</i></b> then carry on and <u>replace me 3</u> then carry on and <b>replace me 4</b><br> EDIT: Fixed bug with replacement of empty span tags
  10. On the first page you need to create a FORM. In the parameters of the form tag you need to set the action value to be the secondary page and set the method to either POST or GET (probably POST). But, there is a problem with the code you already have. The query is only capturing the name - not the ID which you are trying to use as the value in the select options. You need to change that query to caputure the ID as well $query="SELECT id, name FROM series1"; Then on the secondary page you need to capture the submitted form value using either $_POST['series1'] or $_GET['series1'] and use in your query: $query = "SELECT series1.title, author.name, series1.description FROM series1, author WHERE (series1.author_id = author.author_id) AND series1.id = {$seriesID} LIMIT 0 , 30"; $data = mysql_query($query);
  11. I think AJAX is overkill for this. Since this is a checkbox, I assume the address values are predetermined. Simply do the query of the database when building the page and populate the address data into the javascript. Then create a function to run onclick of the checkbox to populate the values. Working example: <html> <head> <script type="text/javascript"> //use PHP code to write these JavaScript variable var address1 = "123 Main Street"; var address2 = "Suite 200"; var city = "Los Angeles"; var state = "CA"; var zip = "97140"; function useSavedAddress(useSaved) { document.getElementById('address1').value = (useSaved) ? address1 : ''; document.getElementById('address2').value = (useSaved) ? address2 : ''; document.getElementById('city').value = (useSaved) ? city : ''; document.getElementById('state').value = (useSaved) ? state : ''; document.getElementById('zip').value = (useSaved) ? zip : ''; return; } </script> </head> <body> <input type="checkbox" name="useSaved" onclick="useSavedAddress(this.checked);" /> Use saved address <br /><br /> Address 1: <input type="text" id="address1" name="address1" /> <br /> Address 2: <input type="text" id="address2" name="address2" /> <br /> City, ST ZIP: <input type="text" id="city" name="city" /> <input type="text" id="state" name="state" size="2" /> <input type="text" id="zip" name="zip" size="5" /> </body> </html>
  12. OK, here is what I understand, and what I would do: You want the shoutbox to show the last 10 messages and updated every 2 seconds if there have been changes. It appears there is a flaw in the JavaScript that populates the return value from the AJAX call. Instead of replacing the current content it sounds like it is appending [need to see the function handleSendChat()]? Here is what I would do: When you do a check every two seconds you could either always grab the last ten results OR do a chek to see if there are newer records since the last call. To even to a check you would first have to do a database query, so I would have the script always pull the last 10 records. But, that doesn't mean you always have to update the content. So, when making the AJAX request include a parameter for lastRecordID. That will include the id of the most current record from the last request. On the initial request the value could be set to false. On the PHP script, do the query to get the last 10 records. Then on the very first record, check to see if the ID matches the ID passed in the AJAX request. If it matches, then simply return false. If it does not match then loop through the 10 records and build the output. The JavaScript that processes the AJAX request output would check the return value. If the value = false, then do nothing. Otherwise populate the returned results.
  13. You just need to define the length of the id fields to an appropriate length. The previous poster simply underestimated how big to make his fields. However, you may want some function to clean up the forum of old posts - that's for you to decide. Making separate tables is a bad idea in my opinion. Only increases the chance of errors. My recommendation, if you are to proceed with this, is to do A LOT of reading about database design and normalization.
  14. That's not a dumb question at all, but yes I have session_start(); right after the opening <?php tag. At the risk of beating a dead horse, are you using session_start() on index.php and again when you do the redirect to display.php? I did some local tests and that is the only thing I can come up with to replicate what you are seeing. Once you use the header funtion to redirect to another page, pretty much all "state" values are lost, session, POST, GET, etc.
  15. What?! No need to change the status of the messages to old and new - simply query for the last 10 records using LIMIT.
  16. How, exactly, do you "scoot" the user to the display page? Did you check the HTML source code when the images don't load to see if there is a value for the image path?
  17. Not quite clear what you are asking. I would expect that the search results would include links back to the pages with the matched words. If it were me I would do something scuh as a title for the page followed by an exerpt of the text with the found word. The title would be a link tothe page: Title of first matched page ... something something something word something something ... Title of second matched page ... something word something something something something ...
  18. Based upon the questions you have I would highly advise not trying to build a forum yourself. Most of your questions are related to database design. With a forum, a good, normalized database design will be key if it gets a lot of traffic. It sounds as if that is not an area where you are strong at. If you were just building a forum for learning purposes I might say go ahead, but not if it is something that a site with a lot of traffic will depend on. Even if you were very skilled I would still suggest against it. Anything you produce is going to have bugs - many of the available, ready to go forums, have been out long enough that many/most of the issues have been found and resolved. Although there is one thing to say about having a custom forum. With the ready-made forums when a security hole is found any sites that use that forum may be at risk until the hole is patched. Because of their widespread use, there are more people looking for and using vulnerabilities against those forums. You should try some out to see which ones have the features you need.
  19. Sasa's suggestion may fix the apparent issue (I was going to suggest encasing the first condition in the IF within parens), but the real issue is why you are not able to retrieve just 10 records. The fact that it shows 10 records pauses and then shows another 10 results is a significant detail. Normally, a page is not delivered to the user until the entire thing has been created (only things like images and such take a while to load). The fact that you are seeing blocks of text appear one after the other suggest that there is definitely something else going on and that there is another loop in place. But, it is apparently due to some other code that was not provided.
  20. Huh? That makes no sense. If you limit your query to 10 results then you will only get 10 results. It appears that is what you are trying to do. Also, are you 100% sure your query is returning results. Sometimes I make minor edits in things while I am working on soemthing else and scratch my head why something no longer works. You are apparently using some custome functions for the database actions, use whatever one you have to echo the number of results to the page and try this: $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time FROM message WHERE chat_id = " . db_input($_GET['chat']) . " AND message_id > {$last} LIMIT 0, 10"; $message_query = db_query($sql); //Loop through each message and create an XML message node for each. while($message_array = db_fetch_array($message_query)) { $xml .= '<message id="' . $message_array['message_id'] . '">'; $xml .= '<user>' . htmlspecialchars($message_array['user_name']) . '</user>'; $xml .= '<text>' . htmlspecialchars($message_array['message']) . '</text>'; $xml .= '<time>' . $message_array['post_time'] . '</time>'; $xml .= '</message>'; }
  21. http://www.phpfreaks.com/tutorial/basic-pagination
  22. What does "isn't working" mean? Are you getting errors? What is it doing or not doing that you expect it to? However, I have to ask, why are you using a variable to only display 10 records? just modify your query to ONLY return the number of records that you want.
  23. First off you have a problem with matching your quote marks in the input tag: <input type="button" value="test" onclick="getVal(); setVisible('layer1');return false' target='_self'" /> You open the onclick with a double quote, but try and close with a single quote. There is also an extra double quote at the end of the target parameter. Second, "name" has only one "a", not two <textarea name="reply" id="reply" naame="reply" rows="3" That should fix most of your problems except one. This line window.onscroll = setTimeout("placeIt('layer1')",500); is failing with the error message "Not implemented".
  24. JavaScript is picky about the case of the functions/properties. You should be using innerHTML
  25. Depends. You said you want it to change color when the mouse hovers over the text field. If that is what you want then use onmouseover/out. But, typically I see that type of functionality for when the user selectes/enters the field.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.