PHP - Php/mysql Array Newbie Help
I created a shell script in OS X which forces my Macbook to connect to a MySQL database to see if my laptop was stolen. I can mark the Macbook as stolen in the database, which would provide me with a series of fuctions; one of these functions allows you to take pictures through the iSight camera and upload to an FTP server. The script and database work well, but now I'm trying to make it more user friendly by making it web-based.
Here is an example of the code I'm having trouble with: $picture = mysql_query("SELECT picture FROM laptops"); $picrow = mysql_fetch_array($picture); if ( $picrow[0] == 0){ echo "<td>" . "<center><a href='start.php?cmd=start&id=$row[UID]'><img src='images/stopped.gif'></center></a>" . "</td>"; } else { echo "<td>" . "<center><a href='stop.php?cmd=stop&id=$row[UID]'><img src='images/started.gif'></center></a>" . "</td>"; } In the database there is a "1" for active and a "0" for inactive. What it's looking to do is ask to see if it's active or inactive. If it's active, it will have a green button, and inactive with have a red button. Eventually I'd like to be able to activate and deactivate functions by pressing the button, but I need to complete step 1 first. Currently this code does work (except for the links of course); however, I need to specify the number in the array ($picrow[0], $picrow[1], etc.) How do I have this populate automatically from 0 to infinity? I made a field in the database called UID (starting at 1) that automatically increments. I'm not sure if this would help or not. Thanks in advance. Similar TutorialsI am fairly new to PHP, coming over from JAVA. In JAVA, you can select an element of an array and set it as a separate variable, such as: String name="": name = array[4]; But in PHP I am trying this: $ban = $banners[$selected_banner]; Where $selected_banner is a random number. Unfortunately, I am gettting the following error... Catchable fatal error: Object of class stdClass could not be converted to string Are arrays in PHP able to be used in such a way? What am I missing? Code: [Select] <?php $verificate = $_GET["ver"]; $username = $_GET["user"]; $password = $_GET["pass"]; $dbh = mysql_connect("localhost","XXXXXX_dtbusre","my database password here") or die(mysql_error()); mysql_select_db("databasename_zxq_dtb") or die(mysql_error()); $sql = "SELECT loggedin FROM entityTable WHERE username=$username"; $result = mysql_query($sql) or die(mysql_error()); while ($line = mysql_fetch_array($result)){ echo $line[0]."\t".$line[1]."\n"; } mysql_close($dbh); if($verificate === "144356455343"){ echo "SURE"; } else{ echo "NOPE"; } ?> I get this: Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 So, I've just recently gotten into the more advanced web scripting after writing static HTML pages for years and I must say it's pretty exciting. I've finally got my home LAMP up and running and I'm really excited about learning PHP and getting into dynamic web content. One of the areas that I'm really interested in is writing applications for my work and that's one of the first things I've been getting into first. I have some PHP code below that is giving me fits though, I'm afraid. MySQL server version: 5.1.49-1ubuntu8.1 (Ubuntu) My goal: I have an HTML page that has a text input, a drop down box and a submit button. The user inputs a username into the text field, and chooses an option from the drop down box and hits the submit button. I would like for a table holding member information to be updated to reflect the new status based on the user input from the forms. My table, named 'members', has the following fields: id (int) (primary) name (varchar) username (varchar) department (varchar) type (varchar) status (int) The status is a 0 or a 1. Effectively a True/False field. Here's the code in question: <?php // Set variables to get the username and the away/here status // also trim the username variable to ensure there are no inadvertent extra whitespace characters at the // beginning or end $username=$_POST["username"]; $username=trim($username); $status=$_POST["statuschange"]; // Check to ensure the username had a value input // This should be ran before the connection to the database is made to lessen impact on the web server // This is a temporary method, the production version should have a JavaScript function to check form input before // being passed on to the web server if (!$username) { echo "No username was submitted, please try again. Redirecting to main page."; echo "<meta http-equiv='refresh' content='3;url=/ns_index.php' />"; exit; } // Set variables to connect to the mysql server and to access the database // root user is for development purposes only. The production version should have a user setup // specifically for accessing the database with restricted privileges $ns_dev_conn=mysql_pconnect("localhost","mysql","mysqlpwd") or die("Could not connect: ".mysql_error()); $dbvar=mysql_select_db("dbname",$ns_dev_conn) or die("Could not select database: ".mysql_error()); // Set variables for the SQL statement and results $statusaway="0"; $statushere="1"; // Create the SQL statements based on the status being either away or here // This method of generating the SQL statement was used based on recommendation by: http://www.php.net/ if ($status=="away") { $status_query=sprintf("UPDATE `members` SET `status`='%s' WHERE `username`='%s'",mysql_real_escape_string($statusaway),mysql_real_escape_string($username)); } else { $status_query=sprintf("UPDATE `members` SET `status`='%s' WHERE `username`='%s'",mysql_real_escape_string($statushere),mysql_real_escape_string($username)); } // Set the variable to determine the result of the query $result=mysql_query($status_query,$ns_dev_conn) or die("Query failed: ".mysql_error()); // Determine if any rows were affected $num_rows=mysql_affected_rows($result, $ns_dev_conn) or die("Hrrmm. . .<b>".$username."</b>'s status could not be changed to <b>".$status."</b>. Please go back and try again. MySQL Error: ".mysql_error()); // This is a development only block of code // Echo all the variables to ensure the proper values are being passed // If these variables aren't being echoed one of the die() functions was passed. // Compare the error message received to the other die() functions to determine what is invalid // To get the variable values comment out the bad expression echo "Username: ".$username; echo "<br />Status (char): ".$status; echo "<br />Status away (int): ".$statusaway; echo "<br />Status here (int): ".$statushere; echo "<br />Server Connection Link ID: ".$ns_dev_conn; echo "<br />Database Selection ID: ".$dbvar; echo "<br />SQL Statement: ".$status_query; echo "<br />Result: ".$result; echo "<br />Number of Affected rows: ".mysql_affected_rows($result); /* This should be uncommented for production version // If $num_rows didn't die than the database was updated // Update the user that the query was successful and then redirect them back to the main page echo $username."'s status was updated to ".$status.". You will be redirected to the main page now."; echo "<meta http-equiv="refresh" content="4;url='/ns_index.php'" />"; */ ?> So, I've tried a bunch of different things, including echoing back all the variables to ensure the connection and SQL statements are correct, in addition I've taken the echoed SQL statement and copied it into phpmyadmin and the statement works with no errors! I've also looked at the mysql_info() return values and the row is being matched, it's just not being changed or affected. Right now when I activate this script it's returning the error associated with die() on mysql_affected_rows(). This is telling me that everything is working, except for the table actually being updated. Also, just for development and testing purposes I've been using the root MySQL user so I'm pretty sure it's not a privilege issue. If anybody could provide some insight into this problem I'd be most appreciative. Thanks. HI - Pulling my hair out .. I'm trying to extract from a 3 dimensional array the data for insert to MySql. It is looping correctly however, and it is inserting, however for some reason I am not getting values for price and quantity, just 0. The array is contained within Code: [Select] $prod_details = ($_SESSION['cart']); if you do a print_r on the the session, you get : Code: [Select] Array ( [22] => Array ( [name] => Turkey Jumbo Pack [price] => 155.25 [count] => 1 ) [20] => Array ( [name] => Chicken Variety Pack [price] => 120.35 [count] => 1 ) ) I am using a nested foreach loop to traverse the array: Code: [Select] $prod_details = ($_SESSION['cart']); foreach ($prod_details as $keyOne=> $value){ $prodID = $keyOne; foreach($value as $keytwo=>$row) { $price = $keytwo['price']; $quantity = $keytwo['count']; } But I all I get out of $price and $quantity when I do an insert is 0. What am I doing wrong ? MANY MANY thanks for all your help ! ! Hi there
I am just finalising my first ever PHP/MYSQL project and I am worried about where to safely keep my connection credentials for the SQL DB.
Currently, I am storing them in ../php/config.php and this works fine, but I am worried as to the security of this
Can anyone advise please
Thanks
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343169.0 How can i save array from inputs, witch is $igraci and it have 5 values, to mysql base, i tryed but in mysql it shows Array. This is form: <form action="dodaj_klan.php" method="post" > <p> <label>Naziv klana:</label> <input name="naziv" type="text" size="20%" /> <label>Web Sajt:</label> <input name="website" type="text" size="20%" /> <label>E-Mail:</label> <input name="email" type="text" size="20%" /> <br /><br /> <label>Igraci klana(5):</label> <input name="lider" type="radio" value="1" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="2" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="3" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="4" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="5" /> <input name="igraci[]" type="text" size="20%" /> <label><i>(obelezi lidera klana)</i></label> <br /><br /> <input class="button" type="submit" name="submit" value="Dodaj" /> </p> </form> Now i wonna save this igraci[] array in mysql, i tried like this but it doesn't work: $igraci = $_POST['igraci']; $query = "INSERT INTO klanovi (naziv, website, email, igraci) VALUES ('{$naziv}', '{$website}', '{$email}', '{$igraci}')"; $result = mysql_query($query, $connection); How can i do this? Thanks.. I have a web server which contains a public site and a private site. I want to be able to test for public or private using the page title and return the appropriate header which contains a different banner, css etc. Firstly - the syntax below seems to be incorrect because it doesnt work correctly. More importantly how do I add all the values to an array and than iterate through it to check for a matching page title? Code: [Select] public function publicSite() { if ($this->getTitle()== 'Home' || 'About Us'||'Registration' || 'Sitemap' || 'Contact Us' || 'Useful Links' || 'Feedback') { return true; } return false; } Then later on I would have: Code: [Select] if ($this->publicSite()) { require($ROOT.'interface/pages/publicheader.php'); } else { require($ROOT.'interface/pages/privateheader.php'); } Thanks heaps! Hello all brilliant minds, I'm a new in all this world of DB and coding and always i tried to avoid it because I think it is very hard (I'm trying to change now). problem: I have a text file (log.txt) have data like below ======================================== > rtrv-ls Command Accepted - Processing OXX 12-02-21 08:44:41 EST EAGLE5 42.0.1-63.38.31 rtrv-ls Command entered at terminal #7. ; OXX 12-02-21 08:44:41 EST EAGLE5 42.0.1-63.38.31 L3T SLT GWS GWS GWS LSN APCI (SS7) SCRN SET SET BEI LST LNKS ACT MES DIS SLSCI NIS gtcen1pls 7-010-4 none 1 2 no D 2 off off off no off gtgdv1pls 7-010-5 none 1 2 no D 2 off off off no off > rtrv-sid Command Accepted - Processing OXX 12-02-21 08:43:43 EST EAGLE5 42.0.1-63.38.31 rtrv-sid Command entered at terminal #7. ; OXX 12-02-21 08:43:43 EST EAGLE5 42.0.1-63.38.31 PCA PCI PCN CLLI PCTYPE 010-010-010 7-055-1 01830 crher1p OTHER ; . . may output like this starting always with > =================================================== Then I have SQL DB that have column with "rtrv-ls" and "rtrv-sid" Requirement : A) Use Php to open the .txt file, I used HTML form so the user can upload the file on the browser then B) Search for the column name as pattern C)Send query to MYSQL to update DB with Data for each column D) Query the Mysql for several possible outputs (I've done this part using HTML form and simple php code as below. <?php // If we got a GET request on the page from HTML part of the code, we will want to store the data in a variable e.g $my_country // So country will be passed via GET and will be stored in $my_country variable. $host="localhost"; $con_usr="aomar"; $con_pass="nokia"; if ($_POST) { $user_input = $_POST['my_log'] ; // We use the request to search in Database and return the result, First step we need to connect to the database // $connect = mysql_connect ($host,$con_usr,$con_pass); // Then we need to select database to run the query and return the result the connection stored in the $connect ressource // if ($connect) { mysql_select_db("eagle",$connect); // We store the query in variable $query becuase is it quite long text; we actually attach our varaiable $my_log passed from HTML // $query = "SELECT `".$user_input."` FROM `ss7`"; //$update="INSERT INTO ss7 ('".$user_input."') VLAUES ('; // SO if user selected Egypt it will be stored in (name=my_country) variable from HTML and will be send via GET // Then we store the query results in a variable called $result $result = mysql_query ($query) ; $arr= mysql_fetch_array($result); echo nl2br ($arr["$user_input"]); //Finally we return what we want from the array. // Print the output as we wish. in case of row data like STP output, use the nl2br to preserve the output as it was written to MYSQL DB // We need to check if the Query return no value (!$arr) , and print corresponding action } //================SECONED PART WHEN I LOAD THE LOG FILE TO BE STORED IN MYSQL================// //close the db mysql_close ($connect); } ?> <html> <body> <form action = "eagle.php?pmode=my_file" method = "POST" enctype="multipart/form-data> <fieldset> <legend> Enter you log file here and click Save: </br> </legend> <label for="my_file"> This Is My Capture File </label> <input type = "file" name ="my_file" style=margin:auto > </input><br/><br/> <input type="submit" value="Upload file"> </fieldset> </form> </body> </html> <html> <body> <title>Eagle Data Base Store</title> <form action = "eagle.php?pmode=my_log" method = "POST"> <fieldset> <legend> Please Select the DB you would like to retrive </legend> <br/><br/> <input type = "radio" name ="my_log" value = "rtrv-serial-num">Serial-Num</input> <input type = "radio" name ="my_log" value = "rtrv-stp">rtrv-stp</input> <input type = "radio" name ="my_log" value = "rtrv-feat">rtrv-feat</input> <input type = "radio" name ="my_log" value = "rtrv-dstn">rtrv-dstn</input> <input type = "radio" name ="my_log" value = "rtrv-rte">rtrv-rte</input> <input type = "radio" name ="my_log" value = "rtrv-trm">rtrv-trm</input> <input type = "radio" name ="my_log" value = "rtrv-slk">rtrv-slk</input><br/> <br/> <input type = "radio" name ="my_log" value = "rtrv-ls">rtrv-ls</input> <input type = "radio" name ="my_log" value = "rtrv-sccpopts">rtrv-sccpopts</input> <input type = "radio" name ="my_log" value = "rtrv-stpopts">rtrv-stpopts</input> <input type = "radio" name ="my_log" value = "rtrv-gsmopts">rtrv-gsmopts</input> <input type = "radio" name ="my_log" value = "rtrv-cmd">rtrv-cmd</input> <input type = "radio" name ="my_log" value = "rtrv-assoc">rtrv-assoc</input><br/> <br/> <input type = "radio" name ="my_log" value = "rtrv-gpl">rtrv-gpl</input> <input type = "radio" name ="my_log" value = "rtrv-ip-host">rtrv-ip-host</input> <input type = "radio" name ="my_log" value = "rtrv-ip-lnk">rtrv-ip-lnk</input> <input type = "radio" name ="my_log" value = "rtrv-secu-trm">rtrv-secu-trm</input> <input type = "radio" name ="my_log" value = "rtrv-secu-user">rtrc-secu-user</input> <input type = "radio" name ="my_log" value = "rept-stat-sys">rept-stat-sys</input><br/><br/> <input type = "radio" name ="my_log" value = "rept-stat-clk">rept-stat-clk</input> <input type = "radio" name ="my_log" value = "rtrv-ctrl-feat">rtrv-ctrl-feat</input> <input type = "radio" name ="my_log" value = "rtrv-tabl-capacity">rtrv-tabl-capacity</input><br/><br/> <input type = "submit" value = "Show Selected Table"/> </fieldset> </form> </body> </html> ==========================================END OF CODE=========================== *** Sorry for the many comments but I want to be sure I remember why I do that . You help is much appreciated (Please note that need to understand more than I need the Code itself) I am creating a site to display some products. For ease of updating I want it to run off a MySQL database. I have created the database and php scripts to output and input data etc. I know want to show that data in my web pages. My question is.... Is it best to insert HTML into the php output script to display the information and make the site look how I want....OR ....... should I create a template of the site in HTML and then somehow call the php output script (and the particular row of the database...) Basically... should I put the html code into the php - OR - put the php into the HTML?? I hope this make sense...... thanks So I'm querying my database to add the results (mapID's) into a PHP array. The MySQL query I used in the below code would usually return 10 values (only 10 mapID's in the database) Code: [Select] while($data = mysql_fetch_array(mysql_query("SELECT mapID FROM maps"))){ $sqlsearchdata[] = $data['mapID']; } Instead the page takes ages to load then gives this error: Quote Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes) It says the error begins on the first line of the above code. I'm assuming this is not the right way to add the value from the MySQL array into a normal PHP array. Can anyone help me? Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) My language table structure looks like : id | english mail_accepted | Your e-mail is accepted. thank_you | Thank you for your visit. What I want to do is, I want to take all these data to an array like : "lang" array And I can use these in the page like Code: [Select] <?php echo "goodbye ".$lang['thank_you']; ?> I know how to take data, lets say Code: [Select] <?php $query = "select * from language.. "; mysql_query($query); ?>But then ?, which function should I use to take the data to my "$lang" array ? firstly i am quite rusty at php/sql so sorry in advance. I have a php script to produce graphs with the GD library, alls working well, but I want to modify it so the data comes from my database. so I connect to the database in the usuall way but the script uses an array $values = array("23","32","35","57","12","3","36","54","32","15","43","24","30"); so I need mysql to out put in the same format This is what I have so far, it prints out the data with some formating, thank you for any help you can offer Gary Code: [Select] // Make a MySQL Connection $query = "SELECT Question, COUNT(Answer) FROM question1 GROUP BY Question"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(Answer)'] ." ". $row['Question'] ." items."; } My current code lists between 1-6 results from a MySQL array. How do I extract the data from the list and put it into its own variable (eg: $result1, $result2 etc.) ? Code: [Select] $ran_x = rand(1,6); $ran_x = rand(1,6); $x_query = "SELECT * FROM `x` ORDER BY RAND( ) LIMIT $ran_x"; $get_x = mysql_query($appearance_query); echo 'x(s): '; echo '<br />'; while($row = mysql_fetch_array($get_x)) { echo $row['Appearance']; } Any help would be great, Thanks, otester Hi Guys, I have been racking my brain all of today trying to get this to work, im pretty new to it all! What im trying to do is use the following code whcih works fine and returns all the correct information in an Array, and insert this into a MySQL DB. Can anyone point me in the right direction? foreach($html->find('div.rsshelper') as $article) { $item['title'] = $article->find('div.prodlistboxbg', 0)->plaintext; $item['link'] = $article->find('.prodimgurl', 0)->href; $item['image_url'] = $article->find('.image-thumb', 0)->src; $item['old_price'] = $article->find('span.text-pricestrike', 0)->plaintext; $item['current_price'] = $article->find('span.text-pricespecial', 0)->plaintext; $item['saving'] = $article->find('span.price-percentage', 0)->plaintext; $articles[] = $item; } print_r($articles); This is the code that generates the Array with the given data. I know how to connect to the DB but how do I get each row into each row of the DB? Thanks Rory I have an array of data from a mysql result. The problem I have is that I want to find out what the next row is going to be in advanced. At the moment I have Code: [Select] while($row = mysql_fetch_assoc($rs) { echo 'Order ID: ' . $row['order_id']; } This just echo's out the order_id of the current row. However I want to find out if the order_id on the next row is going to be the same or different. If it's different I will want to echo out something else. Code: [Select] while($row = mysql_fetch_assoc($rs) { echo 'Order ID: ' . $row['order_id']; //If order_id + 1 is different then echo echo 'Total: ' . $row['total'] } Does anyone know a way round this problem? Thanks I hope I'm not being a vampire here sucking the life out of you guys, but I can't find any resources in google that explains how to properly use this function in a mysql array. All it does is add a url for any urls added in plaintext. Code: --- <?php function hyperlink ($string) { $string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string); return $string; } // mysql connection $result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC"); echo "<table border='0'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>"hyperlink(. $row['ArticleDescription'] .);"</td></tr>"; echo "<tr><td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>"; echo "</tr>"; echo "<td align='left' valign='top'> </td>"; } echo "</table>"; mysql_close($con); ?> --- Error: "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/doofyd5/public_html/trevor/playground/displayarticles.php on line 146" (Clearly an error where I'm abusing the heck out of the bolded line. Any ideas on how to properly code this? I'm trying to insert array of posts categories into MySQL. I'm getting category IDs from drop down list.. ERR: Notice: Notice: Array to string conversion in C:\laragon\*********\includes\functions.php on line 477
Array Array ( [0] => Array ( [0] => 4 [1] => 5 ) )
PHP try { $sql = "INSERT INTO posts_category_ids (post_id, category_id) VALUES"; $insertQuery = array(); $insertData = array(); foreach ($filter_category as $row) { $insertQuery[] = '(?, ?)'; $insertData[] = $id; $insertData[] = $row; } if (!empty($insertQuery)) { $stmt = $this->conn->prepare($sql); $stmt->execute($insertData); //477 } }catch (Exception $e){ echo $e->getMessage(); } }
Hello Can somepne help me with this issue I have a query who is returning some records ID disciplina moduloUfcd idcpDisciplinas anoTurma
58, Comunicação Visual, 8599, 49, 11 60, Comunicação Visual, 134, 49, 10 When i trying to put this into an array with just one line (merge all with number 49 (idcpDisciplinas) and (anoTurma) 11) i can't get the desired output
My sql query is this one select c.idPlan, cD.disciplina, cM.moduloUfcd, p.Nome, t.Turma, a.Ano, c2.curso, c.validCron, c.cronograma, c.dataLimite, c.idProfessor,cM.horas,cM.tempos, c.pdfCronograma, c2.curso, cM.discModulo, cM.idcpDisciplinas, cM.ano as anoTurma from cpDiscProfessores c inner join cpDisciplinas cD on c.idcpDisciplinas = cD.idCpDisciplinas inner join cpModulos cM on c.idCpModulos = cM.idCpModulos inner join professores p on c.idProfessor = p.idProfessor left join turmas t on c.idTurma = t.idTurma inner join anosescolares a on c.idAnoEscolar = a.idAnoEscolar left join cursos c2 on c.idCursos = c2.idCursos where a.Estado = 1;
And in php what i have is this $result = $stmt->fetchAll(PDO::FETCH_ASSOC); $final = array(); $json = array(); foreach ($result as $row) { $moduloUfcd= $row['moduloUfcd']; if (!isset($moduloUfcd[$moduloUfcd])) { $horas= $row['horas']; $final[$moduloUfcd]['idPlan'] = $row['idPlan']; $final[$moduloUfcd]['disciplina'] = $row['disciplina']; $final[$moduloUfcd]['Nome'] = $row['Nome']; $final[$moduloUfcd]['Turma'] = $row['Turma']; $final[$moduloUfcd]['anoTurma'] = $row['anoTurma']; $final[$moduloUfcd]['curso'] = $row['curso']; $final[$moduloUfcd]['validCron'] = $row['validCron']; $final[$moduloUfcd]['cronograma'] = $row['cronograma']; $final[$moduloUfcd]['dataLimite'] = $row['dataLimite']; $final[$moduloUfcd]['idProfessor'] = $row['idProfessor']; $final[$moduloUfcd]['pdfCronograma'] = $row['pdfCronograma']; $final[$moduloUfcd]['discModulo'] = $row['discModulo']; $final[$moduloUfcd]['idcpDisciplinas'] = $row['idcpDisciplinas']; $final[$moduloUfcd]['moduloUfcd'] = array(); } $final[$moduloUfcd]['moduloUfcd'][] = $row['moduloUfcd']; $final[$moduloUfcd]['horas'][] = $row['horas']; $final[$moduloUfcd]['tempos'][] = $row['tempos']; } foreach ($final as $moduloUfcd => $cron) { $json[] = $cron; } echo json_encode($json); What it gives is : [ { idPlan: "60", disciplina: "Comunicação Visual", Nome: "XXXXXXXXX", Turma: "11ºO", anoTurma: "11", curso: "Técnico de Audiovisuais", validCron: "-1", cronograma: "0", dataLimite: "2020-10-30", idProfessor: "168", pdfCronograma: "/XXXXX/pdf/profissionais/cronogramas/Cronograma -Técnico de Audiovisuais-8599.pdf", discModulo: "8599", idcpDisciplinas: "49", moduloUfcd: [ "8599" ], horas: [ "25" ], tempos: [ " 34 " ] } ]
|