HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
OK, for starters then, if it's going to be used across multiple pages, it needs to be a assigned to a session variable... How are the products displayed on a page, are they static or dynamically generated from a database. Regards Huggie
-
Itoto, Am I to assume from this that you're starting again from scratch? Trying to move away from your single index.php Regards Huggie
-
Use a foreach loop... [code]<?php if ($qry['link'] == ""){ // If the link is empty, output message echo "Link not available yet"; } else { $links = explode(",", $qry['link']); // Put the links into an array split on a comma $count = 1; foreach ($links as $link){ echo "Link $count: <a href=$link>$link</a><br>"; // Output the link including the link number $count++; } } ?>[/code] Regards Huggie
-
I thought that he still wanted the <tr> tags in there. My bad. Regards Huggie
-
ok, give this a try... [code]<?php // Maximum number of rows to display $max = 7; preg_match_all('|<tr>.*?</tr>|ms', $myhtml, $matches); for ($i = 0; $i < $max; $i++){ echo $matches[0][$i]; } ?>[/code] Regards Huggie
-
OK, well I'm glad that it worked. You could reduce the overhead even more by including a 'role' column in your database that designates whether the user is 'admin' or not... This way you can do away with the $admin_ids array and use the value from the database to check if their admin or not. Something like this... [code]<?php if ($view3['role'] == "admin"){ echo "{$view3['username']} is an administrator\n"; } else { echo "{$view3['username']} is not an administrator\n"; } ?>[/code] Regards Huggie
-
That's correct, if the username and email don't exist then the number of rows returned will be zero. If they do exist then the number of rows will be greater than zero. Regards Huggie
-
Thanks for that Marky. Regards Huggie
-
Don't call your variable $GET as it's too much like $_GET which is a predefined variable in php. I'll post a simple bit of code for you to just see if it works, then complicate it and fit the other bits around it. I've taken this nearly all from your code so it looks familiar to you. [code] <?php // Connect to the database include 'database.php'; // Query the database and assign the results to a variable $view = "SELECT * FROM users WHERE id = '{$_GET['id']}' LIMIT 1"; $view2 = mysql_query($view) or die("Couldn't execute $sql:\n\n" . mysql_error()); $view3 = mysql_fetch_assoc($view2) or die("Couldn't fetch the results:" . mysql_error()); $user = $view3['username']; $admin_ids = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); foreach ($admin_ids as $id){ if ($view3['id'] == $id){ $admin = "y"; } } if ($admin == "y"){ echo "{$view3['username']} is an administrator\n"; } else { echo "{$view3['username']} is not an administrator\n"; } ?> [/code] Call this code something like testforadmin.php and make sure you pass it a value like this testforadmin.php?id=3 Post any errors that you get here. Regards Huggie
-
OK, you need to use MySQL result... I'm just looking up some code I have that will do the job. Regards Huggie
-
OK, it seems that this has been going on a while, and you've also been fed a lot of trap! Firstly, delete that php.ini file that you created and dropped into that directory. A few have mentioned register_globals but none have actually explained what it means/does. So here goes in it's simplest form: [i]Having register_globals switched on, means that you can refer to a variable in php using the name that was provided in the request object, without the need to specify where it came from.[/i] Example: If I have a form that has one field called 'name' and I use the method 'post' to send it to a php page and I want to use that variable. If register_globals is switched off (by default in newer versions of php), I have to use this... [code=php:0]echo $_POST['name']; [/code] If register_globals is on then I can use this: [code=php:0]echo $name; [/code] It automatically imports 'name' into the variable name space, meaning I don't need to specify $_POST. So for your example, you need to use the following code. [code]<?php $view = "SELECT * FROM users WHERE id = '{$_GET['id']}' LIMIT 1"; $view2 = mysql_query($view); $view3 = mysql_fetch_assoc($view2); $user = $view3['username']; ?>[/code] The above example assumes that the column in the table (users) that contains the unique user ID is called 'id' Regards Huggie
-
ok, and do you want complete code returned or just partial code? I'll explain the question. Do you want the <table> tag along with the first 7 <tr> tags, or just the 7 <tr> tags, or the <table>, the first 7 <tr> tags and then everything after the last <tr> tag? Long winded, but hopefully makes sense... Regards Huggie
-
Is the variable always only going to be one table, or could it contain more than one? Regards Huggie
-
Mozilla has just releases version 2 of it's popular [url=http://www.mozilla.com/en-US/firefox/]Firefox[/url] browser. I've installed and am currently using it, but have noticed that the shortcut keys for both preview (alt+p) and post (alt+s) no longer work. The reason for the post button not working is that alt+s now brings up the history menu. Is there a way around this? I loved the preview and post shortcuts and don't want to have to revert to using the damn mouse! Regards Huggie
-
I'm glad it worked out ok. I see what you mean about the radio buttons but still feel it's been coded incorrectly. I can appreciate using javascript to make one set of options available only if another is selected, but you should still use the appropriate form element. Regards Huggie
-
Can not get e-mail info from login system
HuggieBear replied to mariocesar's topic in PHP Coding Help
FYI, It looks as though you've removed the printerror() function I created. This will cause you problems if your database is ever unavailable. If you don't want that function in there, then change each instance of this: [code=php:0]printerror($sql, mysql_error());[/code] to this [code=php:0]or die("Can't execute: $sql\n\n" . mysql_error()); [/code] Regards Huggie -
OK, on the left hand side where you select the tables to export, select type is sql. On the right hand side, where you have the sql options, select export type INSERT from the drop down. Regards Huggie
-
OK, a session and a cookie, aren't technically the same. If you mean you want to check for a session variable then use the code I've posted but with session... [code]<?php if (isset($_SESSION['discount'])){ include('/home/pire/www/products/DISCOUNT.php'); } else { include('/home/pire/www/products/REGULAR.php'); $_SESSION['discount'] = "value"; } ?>[/code] Regards Huggie
-
Can not get e-mail info from login system
HuggieBear replied to mariocesar's topic in PHP Coding Help
Don't nest your functions, it looks untidy and is harder to trap errors, try this: [code]<?php // Create session session_start(); // Is user logged in if (!$logged_in_user){ echo "You are login as, ".$logged_in_user."."; // Connect to the database mysql_connect("mysql145.secureserver.net", "userregister", "userregister"); // select and execute the query $sql = "SELECT * FROM `userregister` WHERE `name`= '$logged_in_user'"; $result = mysql_query($sql) or printerror($sql, mysql_error()); $row = mysql_fetch_array($result) or printerror($sql, mysql_error()); //then to grab the users email just do: echo "An email was sent to {$result['email']} with the information."; } function printerror($code, $message){ echo "Couldn't run the following code: $code\n\nFailed with the following error: $message\n\n"; } ?>[/code] Regards Huggie -
Can you not use MySQL's [b]MID()[/b] function for this? Regards Huggie
-
I think one of us is confused here. Radio buttons are usually composed of various buttons with the same name, but different values, allowing you to select only one of the options. From what you're showing me, it's indicating that you have two radio buttons, both with a different name, hence independent from each other. If this is the case, then surely a checkbox is what you're after? Regards Huggie
-
In that case use the header() function. [code=php:0]header("Location: $array[0]"); [/code] Regards Huggie
-
This is because there's an internal pointer that gets moved on each time a row is accessed. So if you use a while loop to access all the rows, the next time you try to get a row (by creating another while loop) the pointer is at the end of the result set. Try adding this line after the first while loop: [code=php:0]mysql_data_seek($runquerya, 0); [/code] Regards Huggie
-
Just echo it in a link... [code=php:0]echo "<a href=\"{$array[0]}\">My Link</a>"; [/code] Regards Huggie