
Zorglub
Members-
Posts
15 -
Joined
-
Last visited
Everything posted by Zorglub
-
// Testing if exists if($row['vehicleid'] = $vehicle->VehicleId) { $rowcount=mysqli_num_rows($result); echo "Timestamp: " . $row['timestamp'] . "<br>"; echo "VehicleId: " . $row['vehicleid'] . "<br>"; echo "img: " . $row['img'] . "<br>"; } The url example: https://i.ebayimg.com/images/g/FQ0AAOSw8WdbfU5w/s-l1600.jpg
-
Hi, I am trying to make a latest visited cars segment where I save the image and id of the car the the user sees. But I am lost as how to go from here... // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $imgUrl = $vehicle->Pictures[1]; $getTimeStamp = "SELECT * FROM latest"; $result = $conn->query($getTimeStamp); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')"; if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { if($row['vehicleid'] <> $vehicle->VehicleId) { echo "Timestamp: " . $row['timestamp'] . "<br>"; echo "VehicleId: " . $row['vehicleid'] . "<br>"; } } } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); /////////////////////////////////////////////////////////
-
Hi, I am trying to make a latest visited cars segment where I save the image and id of the car the the user sees. But I am lost as how to go from here... $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $imgUrl = $vehicle->Pictures[1]; $getTimeStamp = "SELECT timestamp FROM latest"; $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')"; if ($getTimeStamp->num_rows > 0) { // output data of each row while($row = $getTimeStamp->fetch_assoc()) { echo "Timestamp: " . $row['timestamp']; } } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close();
-
PHP - How to take an image from an array and save it to MYSQL?
Zorglub replied to Zorglub's topic in PHP Coding Help
I found the solution... To make the picture a variable: $imgUrl = $vehicle->Pictures[1]; $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')"; -
PHP - How to take an image from an array and save it to MYSQL?
Zorglub replied to Zorglub's topic in PHP Coding Help
The array contains url's to the images, so I do not need to upload any images... The data is a JSON url... The whole code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Look at car</title> <link rel="stylesheet" href="./css/style-show-room.css"> </head> <body> <div class="container"> <?php $id = $_GET['VehicleId']; $url = 'https://gw.bilinfo.net/listingapi/api/export'; // provide your username and password here $auth = base64_encode("demo:ocfB6XzF73"); // create HTTP context with basic auth $context = stream_context_create([ 'http' => ['header' => "Authorization: Basic $auth"] ]); // query for data $data = file_get_contents($url, false, $context); // $escaped = json_encode($data); $escaped = json_decode($data); //, JSON_FORCE_OBJECT /*Initializing temp variable to design table dynamically*/ $temp = "<table class='car-list'>"; /*Defining table Column headers depending upon JSON records*/ /*Dynamically generating rows & columns*/ foreach ($escaped->Vehicles as $vehicle) { if($vehicle->VehicleId == $id) { // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$vehicle->Pictures[0]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ///////////////////////////////////////////////////////// // INSERT VIEWED CAR - END $temp .= "<tr>"; $temp .= "<th colspan='4' class='th-style'>" . $vehicle->Make . " " . $vehicle->Model . " " . $vehicle->Variant . "</th>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td colspan='4' class='td-style'>"; for ($p = 0; $p < $vehicle->PictureCount; $p++) { if ($p < 1) { $temp .= "<table class='images-table'>"; $temp .= "<tr>"; $temp .= "<td rowspan='2' class='td-style'>"; $temp .= "<img class='cc-images' src='" . $vehicle->Pictures[$p] . "'>"; $temp .= "</td>"; $temp .= "</tr>"; $temp .= "</table>"; } } $temp .= "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td class='td-style'>Producent: " . $vehicle->Make . "</td>"; $temp .= "<td class='td-style'>Model: " . $vehicle->Model . "</td>"; $temp .= "<td class='td-style'>Variant: " . $vehicle->Variant . "</td>"; $temp .= "<td class='td-style'>Sælger: " . $vehicle->DealerName . "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td class='td-style'>Pris: " . $vehicle->Price . "</td>"; $temp .= "<td class='td-style'>Type: " . $vehicle->PriceType . "</td>"; $temp .= "<td class='td-style'>Kontaktpris: " . $vehicle->CashPrice . "</td>"; $temp .= "<td class='td-style'>Udsalgspris: " . $vehicle->WholesalePrice . "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td colspan='4' class='td-style'>Bil id: " . $vehicle->VehicleId . "</td>"; $temp .= "</tr>"; } } // START $servername2 = "localhost"; $username2 = "root"; $password2 = "Wichmand14"; $dbname2 = "visited"; // Create connection $conn2 = new mysqli($servername2, $username2, $password2, $dbname2); // Check connection if ($conn2->connect_error) { die("Connection failed: " . $conn2->connect_error); } $sql2 = "SELECT * FROM latest LIMIT 3"; $result2 = $conn2->query($sql2); if ($result2->num_rows > 0) { // output data of each row while($row = $result2->fetch_assoc()) { for ($i = 0; $i < 3; $i++) { if ($i < 3) { $temp .= "<tr>"; $temp .= "<td colspan='2'>"; $temp .= "<img class='latest-img' src='" . $row["img"] . "'>"; $temp .= "" . $row["img"] . ""; $temp .= "</td>"; $temp .= "<td colspan='2'>" . $row["vehicleid"]. "</td>"; $temp .= "</tr>"; } } } } else { echo "0 results"; } $conn2->close(); // END /*End tag of table*/ $temp .= "</table>"; /*Printing temp variable which holds table*/ echo $temp; // echo $data; ?> </div> </body> </html> -
Hi Now I don't mean saving the whole array, only number, say 3. How would you do that? My code so far: // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Fun"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$vehicle->Pictures[0]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ///////////////////////////////////////////////////////// But it only inserts "Array()" into to the MYSQL...
-
My try so far...: I want to get the data, then set all the cars up in a list (<li></li>) so I can style it later. <?php //The URL of the resource that is protected by Basic HTTP Authentication. $url = 'https://gw.bilinfo.net/listingapi/api/export'; //Your username. $username = 'demo'; //Your password. $password = 'ocfB6XzF73'; //Initiate cURL. $ch = curl_init($url); //Specify the username and password using the CURLOPT_USERPWD option. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); //Tell cURL to return the output as a string instead //of dumping it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Execute the cURL request. $response = curl_exec($ch); $jsonDecode = json_decode($url, true); echo "<b>Bil:</b> " . $jsonDecode['Vehicles']['Pictures']; //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } //Print out the response. echo $response; ?>
-
PHP: GET JSON from URL and structure it in HTML
Zorglub replied to Zorglub's topic in PHP Coding Help
This example just takes the $response, and put it all in there. I need to control the individual cars so I can style them... -
PHP: GET JSON from URL and structure it in HTML
Zorglub replied to Zorglub's topic in PHP Coding Help
This a example without authentication: <?php $jsonurl = "https://reqres.in/api/users/2"; $json = file_get_contents($jsonurl); $jsonDecode = json_decode($json, true); echo "<b>E-mail:</b> " . $jsonDecode['data']['email']; echo $jsonDecode['data']['first_name']; ?> -
PHP: GET JSON from URL and structure it in HTML
Zorglub replied to Zorglub's topic in PHP Coding Help
The goal is to mark up with html Take at look at the output, it is a cluster, but I want to mark up with HTML: "<td>" . name->model . "<td>" -
I have this code: <?php //The URL of the resource that is protected by Basic HTTP Authentication. $url = 'https://gw.bilinfo.net/listingapi/api/export'; //Your username. $username = 'demo'; //Your password. $password = 'ocfB6XzF73'; //Initiate cURL. $ch = curl_init($url); //Specify the username and password using the CURLOPT_USERPWD option. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); //Tell cURL to return the output as a string instead //of dumping it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Execute the cURL request. $response = curl_exec($ch); //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } //Print out the response. echo $response; ?> But how do I put it into HTML though?