HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
Give this PHPFreaks [url=http://www.phpfreaks.com/tutorials/73/0.php]tutorial[/url] a try... Regards Huggie
-
passing php variable to javascript **SOLVED**
HuggieBear replied to scottybwoy's topic in PHP Coding Help
If you can't get it to work, then can you attach the [url=http://www.codeproject.com/jscript/jsactb/actb.zip]complete source[/url] as I'm assuming you're a member of the site, and I'll take a look, I think I know how to solve it. Regards Huggie -
passing php variable to javascript **SOLVED**
HuggieBear replied to scottybwoy's topic in PHP Coding Help
You need to use the arguments property... Go back to using the implode() function with commas, so your list looks something like this: [pre]Apple, Dell, Mesh, Microsoft[/pre]Then within your javascript function, use the arguments property. So where they have the code looking like this: [code] actb(document.getElementById('textbox_id'),customarray); [/code] Use this: [code] actb(document.getElementById('textbox_id'),arguments); [/code] Regards Huggie -
Thanks Daniel0 That will speed things up for me :) Regards Huggie
-
Will you have a need to paginate your results? e.g. 15 thumbs per page with 'previous' and 'next' buttons at the bottom? Regards Huggie
-
[quote author=Crayon Violent link=topic=110622.msg447548#msg447548 date=1160084785] and if it's the first...well in the forum index just click on the "replies" column to re-sort the posts based on replies. It will show the 0 replies first. [/quote] The problem with this method is that you don't actually get them in any date order then... I want to see the posts with 0 replies, but ordered by date, so I can reply to the most recent ones and work backwards. Regards Huggie
-
If you search these forums for 'upload' I'm sure you'll get loads of hits. It's been asked here so many times. Regards Huggie
-
Anytime my friend :) Huggie
-
It won't, you have your code in the wrong place... Move this: [code=php:0]$db->query("UPDATE users SET uGems=uGems+'$rand_gems' WHERE uID='" . $user['uID'] . "'"); [/code] Inside here: [code] <?php if($rand==1 || $rand==5 || $rand==10 || $rand==15 || $rand==20 || $rand==25){ $rand_gems = rand(1,5); echo "You start to mine with your bronze pickaxe and find $rand_gems gem(s)."; } ?> [/code] You currently have it updating the database if they don't find the gems, not if they do :) Regards Huggie
-
I'd hazard a guess at a few million people (including me) :D I'm assuming as you're posting that you're having problems, if so, you're probably better off posting them in the [url=http://www.phpfreaks.com/forums/index.php/board,34.0.html]3rd Party[/url] forum... Regards Huggie
-
[solved user get a book]select list with array.
HuggieBear replied to redarrow's topic in PHP Coding Help
It's nothing to do with php, it's to do with HTML, and there's nothing wrong with that. Links to check the syntax of both [url=http://www.w3schools.com/tags/tag_select.asp]<select>[/url] and [url=http://www.w3schools.com/tags/tag_option.asp]<option>[/url] [code] <select name="model"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="opel">Opel</option> <option value="audi">Audi</option> </select> [/code] Regards Huggie -
[solved user get a book]select list with array.
HuggieBear replied to redarrow's topic in PHP Coding Help
What were you told was wrong about it, it looks OK to me. Regards Huggie -
Please put [b][[/b][b]code][/b] ... [b][[/b][b]/code][/b] tags around your code to make it more readable. As for your request, try this: [code]<?php // Get the value from the URL $Newsid = $_GET['Newsid']; // Construct and execute the query $query = "SELECT * FROM News WHERE Newsid = '$Newsid'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Loop through the results creating a table for each row while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $main = nl2br($row['Main']); // Change the "\n" to <br> // Echo the code echo <<<HTML <table width="640px" class="style10"> <tr> <td>{$row['Date']}</td> </tr> <tr> <td>{$row['Heading']}</td> </tr> <tr> <td>{$row['Subhead']}</td> </tr> <tr> <td>{$main}</td> </tr> </table> <br /><br /> HTML; } ?>[/code] Regards Huggie
-
passing php variable to javascript **SOLVED**
HuggieBear replied to scottybwoy's topic in PHP Coding Help
I guess it's possible... Maybe give us a bigger overview of what you're doing and we'll see if we can come up with something without re-inventing the wheel. Regards Huggie -
It'd be easier to use [url=http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]heredoc syntax[/url] for this one: [code]<?php echo <<<HTML <td align=left>{$row['date']}</td> <td align=center>{$row['title']}</td> <td align=center> <a href="get_job_details.php?date={$row['date']}&title={$row['title']}&location={$row['location']}"> <img src="flesh/detailsbutton.jpg" alt="Details" </a> </td> <td align=center>{$row['location']}</td> HTML; ?>[/code] Regards Huggie
-
No problem, when I first looked I couldn't find it either so I asked here too... See [url=http://www.phpfreaks.com/forums/index.php/topic,108074.msg434411.html#msg434411]this post[/url]. Always a good idea to search the forums first too :) Huggie
-
passing php variable to javascript **SOLVED**
HuggieBear replied to scottybwoy's topic in PHP Coding Help
I'm afraid that I've never done much with JavaScript and I've only created a few simple applications with AJAX. You're not passing an array to JavaScript though, you're passing it a string. If you wanted to pass it an array you could do away with the implode() function and just return $companies. Regards Huggie -
You still haven't pasted in the closing curley brace! Try this: [code]<?php if(!$_GET['stp']){ ?> <b>You walk into the mine and see loads of rocks..<br> <a href="mine2.php?stp=bronze">Mine with bronze pickaxe</a><br> <?php } elseif($_GET['stp'] == "bronze"){ if($user['uAttackTurns'] <= 4){ echo "You Dont have enough Energy to mine."; exit; } if($user['uPickaxe']=='0'){ echo "You need a pickaxe to mine gems."; exit; } $rand = rand(1,20); if($rand==1 || $rand==5 || $rand==10 || $rand==15 || $rand==20 || $rand==25){ $rand_gems = rand(1,5); echo "You start to mine with your bronze pickaxe and find $rand_gems gem(s)."; } else{ echo "You find nothing but bits of useless rock"; $db->query("UPDATE users SET uGems=uGems+'$rand_gems' WHERE uID='" . $user['uID'] . "'"); } } ?> <a href="mine2.php?stp=bronze"><br>Mine again</a><br>[/code] Regards Huggie
-
It's possible... If you right a commercial script and you make it compatible with multiple databases but you want to provide an out install script with it or something. You might want to assume that the user doesn't know, the type, only the details of where it's located. Regards Huggie
-
passing php variable to javascript **SOLVED**
HuggieBear replied to scottybwoy's topic in PHP Coding Help
You're selecting one column from a table, so what exactly do you want in the array, the company keyed on a numeric index, so the equivilent of: [code]<?php $companies = array('Apple', 'Dell', 'Mesh', 'Microsoft'); echo $companies[2]; // echos Mesh ?>[/code] Or do you want to company as the key, if so, what do you want as the value? It looks as though what you're trying to do is get all the companies into an array and then output them as a single string seperated by commas, is this correct? If the above is correct then this isn't really a situation for foreach... Try this: [code]<?php function company_col(){ $sql = "SELECT company FROM customers"; $result = mssql_query($sql) or die("SQL Error selecting customers"); $companies = array(); while ($row = mssql_fetch_row($result)){ $companies[] = '"'.addslashes($row['company']).'"'; } $companylist = "\t[".implode(",", $row)."]"; echo "$companylist"; } company_col(); // Will return " [Apple,Dell,Mesh,Microsoft]" (without the double quotes) ?>[/code] Regards Huggie -
Hostfreak, The curly braces are used for variable parsing... When a string is enclosed in either double quotes or within the [url=http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]heredoc syntax[/url], the variables are parsed within it. The curly braces are used in 'complex' parsing of variables. The link above will take you to the correct page in the manual, then scroll down slightly until you see the title 'Variable Parsing'. It's an excellent read :D Regards Huggie
-
You mean a way to query the database using a generic function to try and return the type, e.g. MSSQL, MySQL, Oracle, etc. Something like (obviously not real code): [code]<?php $type = db_type($username, $password, $server); echo $type; ?>[/code] If so, then I don't think so, although that would be excellent. I think you'll need to create a custom function with each of the different connection methods, e.g. mysql_connect() - MySQL oci_connect() - Oracle dba_open() - Berkeley DB odbc_connect() - Access etc.. And then loop through until you get a successful response. Regards Huggie [color=red][b]P.S[/b][/color] Did that other code I changed for you bring you any joy at all?
-
Below is an example of getting the default value for each column from the database, putting it into an array and then using it in a form as the pre-filled value... This code assumes I have a table called 'people' that has two columns in it called 'gender' and 'title'. The default value for title is 'Mr' and the default value for gender is 'Male'. [code]<?php // Connect to database include_once('connect.php'); // Select the column details from the table $sql = "DESCRIBE people"; $result = mysql_query($sql); if (!$result){ echo "Couldn't execute <b>$sql</b>: " . mysql_error() . "\n"; } // Put the default values for each column into an array keyed on column name while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $columns[$row['Field']] = $row['Default']; } // Create the HTML form echo <<<HTML <html> <form name="name" action="process.php" method="GET"> <input type="text" name="title" value="{$columns['title']}"> <input type="text" name="gender" value="{$columns['gender']}"> <input type="submit" name="submit" value="Update"> </form> </html> HTML; ?>[/code] Regards Huggie [size=8pt][color=red][b]Edit:[/b][/color] This code has been tested and works[/size]
-
In which order do you want the data displayed, horizontally or vertically? If you're not sure what I mean, check out [url=http://www.phpfreaks.com/forums/index.php/topic,109401.msg441016.html#msg441016]this post[/url] Regards Huggie
-
Do you mean you want to display default information in the form, the default values from the column on the database? Regards Huggie