-
Posts
1,216 -
Joined
-
Last visited
Everything posted by WebStyles
-
From your question, I have no idea what you already have, I don't see any code, I don't even know if you have a database, so, first things first: You must start somewhere. Do you have a MySql database? have you created the table that will hold the data? if not, create it, add some bogus information, then write some code to pull out data, even if it doesn't work. (we like it when people send us the code they already have, at least it shows they're trying). Post code here, and we'll point you in the right direction.
-
newline not working properly - output not correct in email
WebStyles replied to Olivia_koo86's topic in PHP Coding Help
use "\n" instead of '\n'. with single quotes, newline is not inserted properly. -
to store the article id, use a session variable, like this: $_SESSION['article_id'] = 12345; That variable will be available on all your pages as long as you make sure you have session_start(); at the beginning of each .php file. to retrieve stuff from the database, you need to connect to it first, select the database, choose the fields you want to pull out and from which table, then grab the results. check out these functions on php.net: mysql_connect(); mysql_select_db(); mysql_query(); mysql_close(); hope that helps.
-
Reading data from a bunch of files and adding them to one file
WebStyles replied to alphazulu's topic in PHP Coding Help
try something like this: $allText = ''; $masterFile = file_get_contents('master.txt'); $filenames = explode("\n",$masterFile); foreach($filenames as $file){ $allText .= "\n".get_file_contents($file); } file_put_contents('text.txt',$allText); -
http://pt.php.net/manual/en/function.implode.php
-
Reading data from a bunch of files and adding them to one file
WebStyles replied to alphazulu's topic in PHP Coding Help
file_get_contents(); .. file_put_contents(); -
code is fine, but you need to implode the array before emailing it.
-
Query database with text field and checkboxes.
WebStyles replied to animone's topic in PHP Coding Help
this is not the best way to do it, but it will serve nicely as an example. note $started and how it's used to figure out if we need to insert the word 'AND' in the statement. <?php $keyword = '%'.$_POST['city'].'%'; $query = "select * from `database` where"; if(isset($_POST['club']) && $_POST['club'] != ''){ $query .= " `club` like '$keyword'"; $started = 'yes'; } if(isset($_POST['school']) && $_POST['school'] != ''){ if(isset($started) && $started == 'yes') $query .= ' and'; $query .= " `school` like '$keyword'"; $started = 'yes'; } if(isset($_POST['shop']) && $_POST['shop'] != ''){ if(isset($started) && $started == 'yes') $query .= ' and'; $query .= " `shop` like '$keyword'"; $started = 'yes'; } if(isset($_POST['tour']) && $_POST['tour'] != ''){ if(isset($started) && $started == 'yes') $query .= ' and'; $query .= " `tour` like '$keyword'"; } ?> hope this helps -
\r\n characters inserted when user inputs
WebStyles replied to VinceGledhill's topic in PHP Coding Help
according to php.net nl2br() inserts <br> or <br /> before any newline characters, but it doesn't say it removes the newline characters. Personally I've always used str_replace() since it allows for other situations, like just inserting a space instead of a newline. if what you want is an actuall html line break, then nl2br() is the way to go. -
\r\n characters inserted when user inputs
WebStyles replied to VinceGledhill's topic in PHP Coding Help
when you grab the text field you can convert them into <br /> or just remove them with str_replace("\n\r","<br />",$variable); -
I use something like this to build all my dynamic combos: <?php function buildCombo($table,$values,$displayText,$selectedValue,$comboName){ $conn = conn('databaseName'); $output = '<select name="'.$comboName.'" size="1">'; $q = mysql_query("select $values,$displayText from $table order by $displayText",$conn); while($r = mysql_fetch_assoc($q)){ $output .= '<option value="'.$r[$values].'"'; if($selectedValue==$r[$displayText]) $output .= ' selected'; // you can use $values or $displayText to check for selected $output .= '>'.$r[$displayText].'</option>'; } @mysql_close($conn); $output .= "</select>"; return $output; } // to show the comboBox use: echo buildCombo('tableName','fieldWithValues','fieldWithText','selectedValue','nameForSELECTelement'); // fieldWithValues can be the same as fieldWithText if needed ?> (p.s. I just typed all that in as an example, there maybe typo's) hope it helps
-
if they have to logon to vote/rate then you can use their username in a session variable to track which ones they've voted on. this of course will be reset if they logout and then logon again. better to just store their votes in a database.
-
you're quite welcome. Glad to have helped.
-
add order by MAX(score) DESC
-
well, if no one's on your site, no one is looking at the list of online users so it doesn't matter. as soon as someone comes online, the lists gets updated and what's displayed is correct again.
-
so you just want the highest score of each user... ('total' holds the score value) SELECT username,MAX(score) as total FROM highscores_bubblepop group by username LIMIT 0 , 50" p.s. they guy was asking for it. lol
-
javascript runs on all active browsers. it won't run on the closed one, but someone else will run it.
-
sorry, it's the other way round: order by `username`,`score`
-
yes, cause it's ordered by score. if you also want to order by username see my previous post
-
so you're not even going to try? you want one of us to do it for you? that won't help you learn.
-
if you want to order by score and username, do exactly that: ORDER BY `score`,`username`
-
problems using php inside javascript function
WebStyles replied to born_coder's topic in PHP Coding Help
can you post an example of what is stored in your database? -
not sure what you want. page 3 does not start with session_start() so you wont be able to access $_SESSION variables. it also has some errors.
-
SELECT distinct `username`,`score` FROM `highscores_bubblepop` ORDER BY `score` DESC LIMIT 0 , 50