Jump to content

dragonfx76

Members
  • Posts

    13
  • Joined

  • Last visited

dragonfx76's Achievements

Member

Member (2/5)

0

Reputation

1

Community Answers

  1. Hey all, thanks for the help, i found a working solution: if (isset($_GET['zoeknummer'])) { $pdo = new PDO("mysql:host=$dbhost; dbname=$database", $dbuser, $dbpass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $sql = "SELECT lead_content FROM wp_wgbsupicrm_leads"; $res = $pdo->query($sql); // where $pdo is your db connection $flag=false; while ($lead = $res->fetchColumn()) { $data = json_decode($lead); if ($data->zoeknummer == $_GET['zoeknummer']) { echo "Uw plaats voor " ; echo $data->wachtlijstkomplex . ' : ' . $data->wachtlijstplaats . '<br>'; $flag=true; } } if ($flag==false) { echo 'Geen resultaat gevonden met opgegeven nummer. <br> Kijk na of U het nummer correct heeft ingevuld.'; } } Posting it for further reference thanks all again, you guy's helped alot getting to this!
  2. Hey NotionCommotion, I tried out your solution, it ends up the same way it does without it, it gives an 'echo' for each line it looks in. Thanks agian for helping me out here, i'm learning things even if it isn't the solution so i'm very thankfull.
  3. I understand this way of working isn't the best, the database i'm using is created by a plugin i'm using on a wordpress site. i'm afraid i'm stuck with that. What you say about the Array sounds logical, and was indeed something i thought of, again, the logic is there, the code not. It would mean that where now if ($data->zoeknummer == $_GET['zoeknummer']) { echo "Uw plaats voor " ; echo $data->wachtlijstkomplex . ' : ' . $data->wachtlijstplaats . '<br>'; } is the echo should be replaced with something to make the data found in a so called array? then further down the code else { echo 'Geen resultaat gevonden met opgegeven nummer. <br> Kijk na of U het nummer correct heeft ingevuld.'; } this should be gone i geuss.. I hope atleast i get the logic.. next thing i would think of then is that there should be a line saying that 'if' 'array' has content then if (array has data) { echo "Uw plaats voor " ; echo $data->wachtlijstkomplex . ' : ' . $data->wachtlijstplaats . '<br>'; } else { echo 'Geen resultaat gevonden met opgegeven nummer. <br> Kijk na of U het nummer correct heeft ingevuld.'; } So the problem i have now is how do i get that in code? atleast... If my logic does make any sense...
  4. Hi there, thanks for your answer. I understand what you say, just don't know what it's supposed to be in code. Also will this not 'overwrite' previous found results? In the loop there can be multiple results where 'zoeknummer' may result in more then 1 result to 'echo'. If i get the if and echo out it will only show the last result of the query? if (isset($_GET['zoeknummer'])) { $pdo = new PDO("mysql:host=$dbhost; dbname=$database", $dbuser, $dbpass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $sql = "SELECT lead_content FROM wp_wgbsupicrm_leads"; $res = $pdo->query($sql); // where $pdo is your db connection while ($lead = $res->fetchColumn()) { $data = json_decode($lead); if ($data->zoeknummer == $_GET['zoeknummer']) { echo "Uw plaats voor " ; echo $data->wachtlijstkomplex . ' : ' . $data->wachtlijstplaats . '<br>'; } else { echo 'Geen resultaat gevonden met opgegeven nummer. <br> Kijk na of U het nummer correct heeft ingevuld.'; } } } So your suggestion in to make a FALSE flag that would 'echo' what i have now at 'else'? and it would change to 'TRUE' if there is a result found in the loop? As i said, i have no idea how this would work in code, going to look this up, hope maybe in the meantime i can get some explained here aswell? Thanks for the reply! Working on it :-)
  5. Hello there Thanks to some help on this forum i have a working php file. I'm tweaking it at the moment so it will give me a certain text when there is no data found in a database.. The problem is, i think i got the logic, just don't know the code for it. Let me start with showing the code: <?php $dbhost = 'localhost'; $dbuser = '**********'; $dbpass = '**********'; $database = '**********'; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (isset($_GET['zoeknummer'])) { $pdo = new PDO("mysql:host=$dbhost; dbname=$database", $dbuser, $dbpass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $sql = "SELECT lead_content FROM wp_wgbsupicrm_leads"; $res = $pdo->query($sql); // where $pdo is your db connection while ($lead = $res->fetchColumn()) { $data = json_decode($lead); if ($data->zoeknummer == $_GET['zoeknummer']) { echo "Uw plaats voor " ; echo $data->wachtlijstkomplex . ' : ' . $data->wachtlijstplaats . '<br>'; } else { echo 'Geen resultaat gevonden met opgegeven nummer. <br> Kijk na of U het nummer correct heeft ingevuld.'; } } } ?> I understand that the 'while' makes it search the whole database and the if will show the result found. I also understand that the else will show the text when there is no data found in that column, and i understand it will do that for each coluumn no data is found, and there is the problem. I only want it to show the text displaying once. No mather howmuch columns it has searched in. This code now also shows text for all espty searches and will show the result in between all the negative results. The logic i get is that i need to get the 'else' out the 'while' but that's it. Any help would be appreciated, i'm still trying to understand this php language and am learning, I know the solution might be as simple as breaking an egg.. but if u don't know what an egg is.. ;-) Thanks in advance!
  6. Hi there, I hope i can ask something more about this script. It works wonderfull if i upload it to the website as a seperate page. Now i used the code in a wordpress site and there it either breaks the code up, or it returns to the home page. Also, when using this code, is there a way people can see the password a username etc?
  7. Great thanks, it's working perfect!! Should learn more about phph and sql myself, it's planned. But it seems all so complicated o_O
  8. so i should have this? <html> <body> <form method="get"> <input type="text" id="zoeknummer" name="zoeknummer"/> <input type="submit" name="Zoek" value="Zoek" onclick="" /> </form> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (isset($_GET['zoeknummer'])) { $pdo = new PDO("mysql:host=".localhost.";dbname=".DATABASENAME,USERNAME,PASSWORD); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $sql = "SELECT lead_content FROM lead"; $res = $pdo->query($sql); // where $pdo is your db connection while ($lead = $res->fetchColumn()) { $data = json_decode($lead); if ($data->zoeknummer == $_GET['zoeknummer']) { echo $data->komplex . ' : ' . $data->plaats . '<br>'; } } }?> </body>
  9. I use the script one 2 pages is it safe to share a link here?
  10. Notice: Undefined variable: GET in /home/sbgw/public_html/test2.php on line 17 <form method="GET"> <input type="text" id="zoeknummer" name="zoeknummer"/> <input type="submit" name="Zoek" value="Zoek" onclick="" /> </form> if ($GET["zoeknummer"] != ""){ echo"test <br>";
  11. Hey there, again thanks for the fast reply.. I used the code, it doesn't give an error, but it also doesn't show results.
  12. Hello there, thanks for the fast reply. Concerning the structure in the database, i'm aware this makes it alot harder, the thing is that i don't build the database, i use a plugin for wordpress where it just takes info from a excel cheat and makes leads from it on the website. I'm afraid i have to work with the structure this pluging makes. No clue how to change it in the plugin it self. I did change the POST to GET What i did find so far is that i can 'explode' the field value being: {"zoeknummer":"554477","komplex":"test 4","plaats":"84","versturen":null} into arrays.. No idea how to, and no idea what it mean. I understand it makes the value into different arrays where i then can say if array (where the zoeknummer would be) = 'value entered in the search field' then 'echo' array with value komplex & plaats.. Hope this does make any sence i typed here.. trying to explain something i don't really get is pretty hard. I appreciate all help given, and i would change the database if i know how to and if it still would be working with the plugin then.. ps the change from POST to GET gave an error..
  13. Hello all. First let me explain what the final result should be :-) I want a page with nothing more then a search field. People can give a number in here, and that number will show them, depending on how much hits a result about let's say "ItemAA" has "itemBB" it's possible they have more "itemAA" matches with the number they give. The number is person related, so no person can have the same numbers. Now i used a plugin to create a database of this (a crm tool) where we can export and import using excel files. There is a contact form attached to it where some1 can enter data without using the excel cheat. What's ive got so far: <html> <body> <form method="post"> <input type="text" id="zoeknummer" name="zoeknummer"/> <input type="submit" name="Zoek" value="Zoek" onclick="" /> </form> <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if ($_POST["zoeknummer"] != ""){ echo"test <br>"; $dbhost = 'localhost'; $dbuser = 'database user'; $dbpass = 'database pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Kan geen connectie maken: ' . mysql_error()); } $sql = 'SELECT lead_content FROM wp_wgbsupicrm_leads'; mysql_select_db('database name'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Kan geen gegevens vinden: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "Resultaat:" . $row['lead_content'] . " <br> ". "--------------------------------<br>"; } echo "Gegevens ontvangen\n"; mysql_close($conn); }?> </body> test Resultaat:{"zoeknummer":"554477","komplex":"test 4","plaats":"84","versturen":null} -------------------------------- Resultaat:{"zoeknummer":"556478","komplex":"test 3","plaats":"51","versturen":null} -------------------------------- Resultaat:{"zoeknummer":"112255","komplex":"test 2","plaats":"12","versturen":null} -------------------------------- Resultaat:{"zoeknummer":"110022","komplex":"Test 1","plaats":"1","versturen":null} -------------------------------- Gegevens ontvangen What i'm missing and where it goes wrong.. it shows ALL data and i want that when a person enters the number what you see behind "zoeknummer": will result in an output of only "komplex": and "plaats" i have no idea how to get there since this toke me almost 2 full day's to get to this point.. and i know it might be as simple as baking an egg.. if u don't know what an egg is that is also pretty hard ;-) Any help would be appreciated. I'm trying to learn php and mysql here..
×
×
  • 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.