
molsonbubba
Members-
Posts
14 -
Joined
-
Last visited
molsonbubba's Achievements

Newbie (1/5)
0
Reputation
-
OK, really not sure I understand this now. Changing db columns to Null = Yes fixed the issue. Please help to understand why. Thanks guys!
-
nope, never mind, keys are correct. just checked again. sorry. keays are repeating though as in not unique. any pointers how to make the code work correctly?
-
I am doing something wrong with the the array it seems. $var_dump shows every key in the array as [0] ?
-
nope no errors. how do i initilize this array, something like this would be correct? $assets = array(); $assets = ('locationID' => $row['locationID'], 'itemID' => $row1['itemID'], 'typeID' => $row1['typeID'], 'quantity' => $row1['quantity'], cut down version of $var_dump($assets); array(4) { ["locationID"]=> object(SimpleXMLElement)#8 (1) { [0]=> string( "66014546" } ["itemID"]=> object(SimpleXMLElement)#9 (1) { [0]=> string(13) "1005281245364" } ["typeID"]=> object(SimpleXMLElement)#10 (1) { [0]=> string(5) "10246" } ["quantity"]=> object(SimpleXMLElement)#11 (1) { [0]=> string(1) "1" } } array(4) { ["locationID"]=> object(SimpleXMLElement)#6 (1) { [0]=> string( "66014546" } ["itemID"]=> object(SimpleXMLElement)#13 (1) { [0]=> string(13) "1008808366433" } ["typeID"]=> object(SimpleXMLElement)#14 (1) { [0]=> string(5) "10246" } ["quantity"]=> object(SimpleXMLElement)#15 (1) { [0]=> string(1) "1" } } array(4) { ["locationID"]=> object(SimpleXMLElement)#12 (1) { [0]=> string( "66014546" } ["itemID"]=> object(SimpleXMLElement)#10 (1) { [0]=> string(13) "1008944485266" } ["typeID"]=> object(SimpleXMLElement)#9 (1) { [0]=> string(5) "18610" } ["quantity"]=> object(SimpleXMLElement)#8 (1) { [0]=> string(1) "1" } } array(4) { ["locationID"]=> object(SimpleXMLElement)#11 (1) { [0]=> string(
-
I have been working on this for days now, I am stuck, need your guys help please. I am trying to fetch XML from URL, get into to an array and then into mysql db. XML has 797 lines. Number of lines may be less one day and greater the next. The code I have so far inserts same line 797 times lol instead of 797 unique lines once . XML data is all integer. I tried foreach ($array as $key =>$val) as well, I cannot get it to work. XML and code is below. (XML is cut down from 797 lines for purposes of this post). locationID, itemID, typeID, quantity only are needed. <eveapi version="2"> <currentTime>2013-11-30 20:03:22</currentTime> <result> <rowset name="assets" key="itemID" columns="itemID,locationID,typeID,quantity,flag,singleton"> <row itemID="255941808" locationID="66011858" typeID="27" quantity="1" flag="70" singleton="1" rawQuantity="-1"> <rowset name="contents" key="itemID" columns="itemID,typeID,quantity,flag,singleton"> <row itemID="1000634952561" typeID="24699" quantity="1" flag="116" singleton="1" rawQuantity="-1"/> <row itemID="1005070355787" typeID="940" quantity="1" flag="116" singleton="1" rawQuantity="-1"/> <row itemID="1005259834973" typeID="40" quantity="3646" flag="117" singleton="0"/> </rowset> </row> <row itemID="730126633" locationID="66014546" typeID="27" quantity="1" flag="4" singleton="1" rawQuantity="-1"> <rowset name="contents" key="itemID" columns="itemID,typeID,quantity,flag,singleton"> <row itemID="1006719601082" typeID="10246" quantity="1" flag="4" singleton="1" rawQuantity="-1"/> <row itemID="1008808286035" typeID="10246" quantity="1" flag="4" singleton="1" rawQuantity="-1"/> <row itemID="1012628971303" typeID="18610" quantity="4" flag="4" singleton="0"/> </rowset> </row> </rowset> </result> <cachedUntil>2013-11-30 21:29:29</cachedUntil> </eveapi> <?php // Request API from server and create array from returned XML $keyID="somekey"; $vcode="somevcode"; $characterID="someid"; $url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID=".$keyID."&vcode=".$vcode."&characterID=".$characterID.""; $data = file_get_contents($url); $list = new SimpleXMLElement($data); foreach ($list->result->rowset->row as $row) foreach ($row->rowset->row as $row1) { $assets[] = array ('locationID' => $row['locationID'], 'itemID' => $row1['itemID'], 'typeID' => $row1['typeID'], 'quantity' => $row1['quantity'], ); } //Connection settings require_once ($_SERVER["DOCUMENT_ROOT"]."/includes/dbconnection_local_corpassets.php"); //Connection settings from above line, not in live code $host="localhost"; // Host name $username="someuser"; // Mysql username $password="somepass"; // Mysql password $db_name="somed"; // Database name try { $pdo = new PDO('mysql:host=localhost;dbname=evecorp', $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec ('SET CHARACTER SET "utf8"'); } catch(PDOException $e) { echo "ERROR!: " . $e->getMessage() . "<br/>"; die(); } echo date('l, F jS Y.') . "<br/>"; echo "Connection to " . $myserver . " established." . "<br/>"; echo "<br/>"; //Try to insert, count # of records in array $pdo->beginTransaction(); try { $countArray = count($assets); echo "We have $countArray records to enter into the database"; $stmt = $pdo->prepare('INSERT INTO `assets` (`locationID`, `itemID`, `typeID`, `quantity`) VALUES(:locationID, :itemID, :typeID, :quantity);'); foreach ($assets as $row1) $affectedRows = $stmt->execute(array(':locationID'=>$row['locationID'], ':itemID'=>$row1['itemID'], ':typeID'=>$row1['typeID'], ':quantity'=>$row1['quantity'])); print_r($pdo->errorInfo()); $pdo->commit(); } catch (PDOException $e) { echo "ERROR!: " . $e->getMessage() . "<br/>"; die(); } echo "<br/>" . "Database $db_name updated with $affectedRows row(s)."; ?>
-
This is the code I tried. It does not work. There are no errors. The drop down box has Please Select and one empty line below. $items = "|Please Select[c]\n"; $conf =& JFactory::getConfig(); $host = 'localhost'; //replace your IP or hostname $user = 'xxxx'; //database user $password = 'xxx';//database password $database = 'test_db'; //database name $debug = $conf->getValue('config.debug'); $options = array ( 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database ' ); $db =& JDatabase::getInstance( $options ); if ( JError::isError($db) ) { header('HTTP/1.1 500 Internal Server Error'); jexit('Database Error: ' . $db->toString() ); } if ($db->getErrorNum() > 0) { JError::raiseError(500 , 'JDatabase::getInstance: Could not connect to database <br />' . 'joomla.library:'.$db->getErrorNum().' - '.$db->getErrorMsg() ); } $db->debug( $debug ); $db =& JFactory::getDBO(); $db->setQuery("SELECT corpprice_darkochre, postdate FROM tableoreapi"); $result = $db->loadObjectList(); foreach ($result as $r) $items .= $r->corpprice_darkochre . '|' . $r->postdate . "\n"; return $items;
-
i am trying to dynamically populate one dropdown box. i am using rsform pro by rsjoomla generated form. the code they suggest is linked above but it does not work. their tech support us not of any help at all. i am a novice with all of this. it seems simple from what i googled and read so far but it just wont work for me. if any one can help it woluld be great, if not just let me know please that it cant be done and i will look at other solutions to my problem. thanks guys.
-
http://www.rsjoomla.com/support/documentation/view-article/94-auto-populate-a-list-from-a-table.html
-
I do not believe that I do. That's all of it.
-
Haha...well that was just silly of me, I missed the SELECT query. I have been staring at the same thing way too much. Unfortunately it did not make it work. Still <option value=">"</option> in the dropdownbox. $options = "|Please Select[c]\n"; $host="localhost"; // Host name $username="xxxxxxxxxx"; // Mysql username $password="xxxxxxxx"; // Mysql password $db_name="test_db"; // Database name $tbl_name="test_table"; // Table name //Connect to server and select database. $conn = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(! $conn){ die('Could not connect: ' . mysql_error());}echo "Connected successfully\n"; $result = mysql_query("SELECT * FROM test_table" ) or die(mysql_error()); $options = ''; while($r = mysql_fetch_object($result)); { $options .= "<option value='$r->id'>$r->postdate</option>\n"; } return $options;
-
I see <option value=">"</option> in the dropdownbox with the suggested script below by Barand. I noticed there are no ' at $r->corpprice where they are present at '$r->id'. Adding ' did not change the outcome. Thank you. Going to Chapters to see if they got any books . <?php $options = "|Please Select[c]\n"; $host = 'localhost'; $user = 'xxxx'; $password = 'xxxx'; $database = 'test_db'; $link = new mysqli($host, $user, $password, $database); if (mysqli_connect_errno()) { die('Unable to connect to database [' . $db->connect_error . ']'); } $options = ''; while($r = mysql_fetch_object($result)); { $options .= "<option value='$r->id'>$r->postdate</option>\n"; } return $options; ?>
-
Thanks guys. It is not working. I tried both suggestions. I get same reult as before...a dropdown box that is empty. This is beyond frustrating.
-
Thanks. With this array prints and all seems OK except the dropdown down does not populate. $items = "|Please Select[c]\n"; $host="localhost"; // Host name $username="xxxxxxxxxx"; // Mysql username $password="xxxxxxxx"; // Mysql password $db_name="test_db"; // Database name $tbl_name="test_table"; // Table name //Connect to server and select database. $conn = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(! $conn){ die('Could not connect: ' . mysql_error());}echo "Connected successfully\n"; $result = mysql_query("SELECT * FROM test_table" ) or die(mysql_error()); while($r[]=mysql_fetch_assoc($result)); echo "<pre>"; print_r ($r); echo "</pre>"; foreach ($result as $r) $items .= $r->id . '|' . $r->corpprice . "\n"; return $items;
-
I am stuck. I am trying to populate a dropdown box in my form from MySql database. Connection to db is working but I can't seem to be able to get the dropdown box on my form to populate...all I see is Please Select with an empty clickable row below. Help!? Thanks. $items = "|Please Select[c]\n"; $host="localhost"; // Host name $username="xxxxxxxxxx"; // Mysql username $password="xxxxxxxx"; // Mysql password $db_name="test_db"; // Database name $tbl_name="test_table"; // Table name //Connect to server and select database. $conn = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(! $conn){ die('Could not connect: ' . mysql_error());}echo "Connected successfully\n"; $result = mysql_query("SELECT * FROM test_table" ) or die(mysql_error()); foreach ($result as $r) $items .= $r->id . '|' . $r->corpprice . "\n"; return $items;