Jump to content

PHPNEWTOIT

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Everything posted by PHPNEWTOIT

  1. Hi I have played with the code and cant get it to work with the kw included but its working fine for the nid using the following incoming url. When I add in the kw it returns array so it I think its nearly there but not sure what happened. http://www.website.com/?nid=1 http://www.website.com/?nid=1&kw=test <?php // get or post parameter name $GLOBALS['ct_get_parameter_name'] = 'nid'; $GLOBALS['ct_default_number_id'] = 0; // Sitelinks $GLOBALS['keywords'] = 'kw'; // source_id => phone number $GLOBALS['numbers'] = array( 0 => array ('0844 000 3000'), 1 => array( '0844 000 0300', 'keywords' => array( 'test' => '0844 000 0350', 'new' => '0844 000 0351' ) ), 2 => array('0844 000 0301'), 3 => array('0844 000 0302'), ); session_start(); if (array_key_exists($GLOBALS['ct_get_parameter_name'], $_REQUEST)) { $_SESSION['ct_source'] = $_REQUEST[$GLOBALS['ct_get_parameter_name']]; } if (array_key_exists($GLOBALS['keywords'], $_REQUEST)) { $_SESSION['ct_source'] = $_REQUEST[$GLOBALS['ct_get_parameter_name1']]; } function get_phone_number() { $numbers =& $GLOBALS['numbers']; $default_number_id = $GLOBALS['ct_default_number_id']; if (isset($_SESSION['ct_source'])) { if (array_key_exists($_SESSION['ct_source'], $numbers)) { if (!empty($_REQUEST['kw']) && array_key_exists($_REQUEST['kw'], $numbers[$_SESSION['ct_source']]['keywords'])) { return $numbers[$_SESSION['ct_source']]['keywords'][$_REQUEST['kw']]; } return $numbers[$_SESSION['ct_source']][0]; } else { // otherwise return first number return $numbers[$default_number_id]; } } else { // return first number return $numbers[$default_number_id]; } } ?> <?php echo get_phone_number(); ?> Also for some reason it would not let me post the php so excuse the text version. Many thanks Roy
  2. Hi Thanks for the code help. I will have a little play with it and see how it goes. Currently the nid array is around 1800 lines long and with the keywords added it will be about 3600+ lines long. Would I be better removing this from the script and try adding the nid's into keyword combinations in a database. Would this help reduce the overhead. Thanks Roy
  3. Hi If the nid=1 with no keyword coming in via the URL I would like it to return the result from just the nid=1 so from the code I already have it would return '0844 000 0300'. (This part works fine) Then I want to extend the array to use a totally different set of numbers if the incoming URL has a nid=1&kw=test. So in the array I would want to add a new number for this for example 0844 000 0350. Again if the nid=1&kw=new in the array this would have a number of 0844 000 0351 for example and so on. So in the array nid=1 would exist once for nid like it does now but could have multiple nid=1 with various kw options. If the incoming URL does not contain a nid or a kw it would defualt like it does now to 0 => '0844 000 3000' I am stuck on how to make the array do want I want and the php changes. So any help is much appreciated. Roy
  4. Hi This is the part I am stuck on, how to add into the array and php code the following: 1) The nid part on its own is working fine and has a default value to return if a nid does note exist of '0844 000 3000' 2) I then want to add to the array and php code the ability to show the nid if its in the incoming url and then extend the code to say if it has a nid&kw to look into the array and find where nid=1@kw=help 3) So I assume the array would look something like 1 "test" => '0844 000 0350', and if this was in the incoming url (http://website.com/?nid=10&kw={keyword} it would display a different phone number from the array being 0844 000 0350. Obviously I have not added this part to the code as I am stuck on how to ammend the PHP and the array. Thanks Roy
  5. Hi I currently pass a URL to our website as follows: http://website.com/?nid=10 but want to extend this to include a keyword from google as well. For example http://website.com/?nid=10&kw={keyword}. However it may not always have a keyword so if it does not it needs to just use the nid array. This is the current script, how do I go about changing it so that if it just contains a nid and no keyword it will do one search of the array and return the result, and if it does have a nid&keywordod it returns something different. For example if it had nid=1 it would return 0844 000 0300 and if it had nid=1&kw=help it would return 0844 000 0350 Thats what I am looking to achieve. Is this possible and how do I change the array. I have had a little attempt but not sure what I am doing and just got coding errors. <?php $GLOBALS['ct_get_parameter_name'] = 'nid'; $GLOBALS['ct_default_number_id'] = 0; // source_id => phone number $GLOBALS['numbers'] = array( 0 => '0844 000 3000', 1 => '0844 000 0300', 2 => '0844 000 0301', 3 => '0844 000 0302', ); session_start(); if (array_key_exists($GLOBALS['ct_get_parameter_name'], $_REQUEST)) { $_SESSION['ct_source'] = $_REQUEST[$GLOBALS['ct_get_parameter_name']]; } function get_phone_number() { $numbers =& $GLOBALS['numbers']; $default_number_id = $GLOBALS['ct_default_number_id']; if (isset($_SESSION['ct_source'])) { if (array_key_exists($_SESSION['ct_source'], $numbers)) { return $numbers[$_SESSION['ct_source']]; } else { // otherwise return first number return $numbers[$default_number_id]; } } else { // return first number return $numbers[$default_number_id]; } } ?> Many thanks in advance. Roy
  6. Hi Thanks for the code as soon as I changed the part you gave me it went through. However I have that code at the top of the page as you said and used the original code and it came up with no errors again just a blank page. Can you check if its in the correct place and anything else I can check to ensure it works as it will save me ages. Thanks again for you help Roy <?php ini_set('display_errors',1); error_reporting(E_ALL); $hostname = "localhost"; $database = "sextoys"; $username = "sextoys"; $password = "sextoys"; mysql_connect($hostname, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query="SELECT t1.title AS lev1, t1.sectionID AS id1, t2.title as lev2, t2.sectionID AS id2, t3.title as lev3, t3.sectionID AS id3, t4.title as lev4, t4.sectionID AS id4 FROM jss_sections AS t1 LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID where t1.title='Main Section'"; $id1 = -1; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ( $row['id1'] != $id1 ) { echo $row['lev1'] . "<br/>\n"; $id2 = -1; $id3 = -1; $id4 = -1; $id1 = $row['id1']; } if (isset($row['id2'] && $row['id2'] != $id2 )) { echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n"; $id3 = -1; $id4 = -1; $id2 = $row['id2']; } } mysql_close(); ?>
  7. Hi I have tried everything tonight to try and fix this all I know at the moment is that the issue is in the 2nd part of the script the 2nd if statement. $query="SELECT t1.title AS lev1, t1.sectionID AS id1, t2.title as lev2, t2.sectionID AS id2, t3.title as lev3, t3.sectionID AS id3, t4.title as lev4, t4.sectionID AS id4 FROM jss_sections AS t1 LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID where t1.title='Main Section'"; $id1 = -1; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ( $row['id1'] != $id1 ) { echo $row['lev1'] . "<br/>\n"; $id2 = -1; $id3 = -1; $id4 = -1; $id1 = $row['id1']; } if (isset($row['id2'] && $row['id2'] != $id2 )) { echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n"; $id3 = -1; $id4 = -1; $id2 = $row['id2']; } } mysql_close(); ?> If I stop the code at the 2nd if I get one result through which is correct for that level. The 2nd part of the script should bring out a further 80+ result but I just get a blank screen. I have tried DEBUG and get no errors, I have PHP error reporting on and it shows nothing wrong but all I get is this blank page. Any help please. Roy
  8. Hi This query was written by a query coder who does not know php but is excellent with queries but I cant seem to get it to run. I just get a blank page. <?php $hostname = "localhost"; $database = "sextoys"; $username = "sextoys"; $password = "sextoys"; mysql_connect($hostname, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query="SELECT t1.title AS lev1, t1.sectionID AS id1, t2.title as lev2, t2.sectionID AS id2, t3.title as lev3, t3.sectionID AS id3, t4.title as lev4, t4.sectionID AS id4 FROM jss_sections AS t1 LEFT JOIN jss_sections AS t2 ON t2.parent = t1.sectionID LEFT JOIN jss_sections AS t3 ON t3.parent = t2.sectionID LEFT JOIN jss_sections AS t4 ON t4.parent = t3.sectionID where t1.title='Main Section'"; $result=mysql_query($query); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } while ($row = mysql_fetch_assoc($result)) { if ( $row['id1'] != $id1 ) { echo $row['lev1'] . "<br/>\n"; $id2 = -1; $id3 = -1; $id4 = -1; $id1 = $row['id1']; } if ( isset($row['id2'] && $row['id2'] != $id2 ) { echo $row['lev1'] . " >> " . $row['lev2'] . "<br/>\n"; $id3 = -1; $id4 = -1; $id2 = $row['id2']; } if ( isset($row['id3'] && $row['id3'] != $id3 ) { echo $row['lev1'] . " >> " . $row['lev2'] . " >> " . $row['lev3'] . "<br/>\n"; $id4 = -1; $id3 = $row['id3']; } if ( isset($row['id4'] && $row['id4'] != $id4 ) { echo $row['lev1'] . " >> " . $row['lev2'] . " >> " . $row['lev3'] . " >> " . $row['lev4'] . "<br/>\n"; $id4 = $row['id4']; } } mysql_close(); mysql_free_result($result); ?> I have tested the query on its own and it seems to work ok as well as the php code upto the second if statement as as soon as i include that nothing shows anymore. Can anyone see what I have done wrong. Thanks in advance Roy
  9. Hi If it is very complex to code does anyone know of any software that can do it. Thanks Roy
  10. Hi I am trying to produce a specification database with results coming out similar to the link enclosed. http://212.74.40.3/getdata.asp?page=3&id=D4668381-868B-4D2A-83B3-6CEBFE545F5E&search=5DFF947A-F837-4FB5-BD7B-15E2DCC7EF39&s=0 Obviously they have like CPU with a Blue Background and then processor and cpu with white background this then goes back to blue for Motherboard. What I am not sure how to do is create the PHP to make something similar and also if for example a title in the database is blank how I would exclude this from the HTML table. So basically I want to create a master cateogry name in mysql and then its sub cats? How do I go about doing this or is is better to code this manually? I then create the tables for the specification Title and then add into the database the content but how do I stop anything that is not filled in from showing. Is this possible. If anyone can give me some guidance and possible code to get me started I would be very grateful, im ok at creating the tables but never got data back out to html tables yet in this format. Thanks Roy
  11. Hi I am stuggling with code to change the phone number displayed on the website depedning on the incoming link. For example the incomings links will be like this:- http://www.mysite.com/index.php?a=1 http://www.mysite.com/index.php?a=2 http://www.mysite.com/index.php?a=3 It work ok until someone uses no incoming link for example http://www.mysite.com/index.php any ideas how I can fix this please. Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 10 Notice: Undefined variable: referer in C:\Program Files\EasyPHP 2.0b1\www\y3kdemo\templates\track.php on line 13 default no to show <?php $phoneno = 'somedefaultvalue'; if(isset($_GET['a'])) { $referer = $_GET['a']; } switch($referer) { case '1': $phoneno = 'phone for campaign 1'; break; case '2': $phoneno = 'phone for campaign 2'; break; default: $phoneno = 'default no to show'; break; } echo $phoneno; ?> Many thanks for your help. Roy
  12. Hi I have a database table called 2004_English and a table called Male which hold lots fo numbers. I want to calculate the SUM of all the numbers in the table but cant seem to get it to work. I have tried many alternatives but it comes back with either Array or wont run at all. Here is the code I have been playing with:- <?php $query = "SELECT SUM(`2004_English`.Male) FROM `2004_English`"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "$row \n"; } ?>
  13. Hi I am using file get contents as shown below but when I then include this page with my own Header and Footer it looks in the wrong location for the images. What could I add to this script so it gets all the images from the remote server. Basically I have been given permission to display content and wrap it around my own headers and footers. I cannot use an Iframe so I think my only solution is file_get_contents but need help on getting the paths correct. <?php $uri = 'https://www.testsite.com'; $html = file_get_contents($uri); if($html !== FALSE) { $html = preg_replace('/<head>/i', "<head>\n<base href='$uri'>\n", $html); echo $html; } else { // error message here... } ?> Many thanks PHPNEWTOIT
×
×
  • 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.