亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將圖像值從語句中的變量傳遞到另一個 PHP 文件

如何將圖像值從語句中的變量傳遞到另一個 PHP 文件

PHP
絕地無雙 2022-11-04 16:45:55
嘿,所以我試圖從我的 PHP 文件中傳遞值,我將數據從數據庫中拉到另一個 PHP 文件到一個標簽,我試圖在我進行查詢的同一個文件上顯示我的圖像,它確實有效,但我需要它在另一個文件中。謝謝    if($image!="")    {        $res = mysqli_query($link,"SELECT * FROM lug_num WHERE lug_id= $image");        $array = array();        ?><br><br><div id = img_lug><?php        while($row=mysqli_fetch_array($res))        {                        global $img;                        $img = $row["image"];            //echo $img;                        ?><img src="<?php echo $img;  ?>"  width='200' height='200' /><?php                                    }            ?></div><?php這是我獲取并可以顯示圖像的文件,我需要另一個文件中的 $img 變量更新所以我嘗試了會話它沒有工作說我有太多的會話我嘗試了功能相同的交易不想工作有什么方法可以用腳本完成嗎?謝謝
查看完整描述

2 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

ajax.php


<?php

    $link=mysqli_connect("localhost","root","123456");

    mysqli_select_db($link,"demo");

     error_reporting(0);

    $make =$_GET["make"];

    $model = $_GET["model"];

    $year = $_GET["year"];

    $oem = $_GET["oem_number"];

    $lug = $_GET["lug_number"];

    $image = $_GET["lug_number"];



if($make!="")

{


    $res = mysqli_query($link,"SELECT * FROM models WHERE make_id= $make");

    echo "<select id='modeldd' onchange='change_model()'>";

    echo "<option selected = '' disabled=''>";echo "Select Model";echo "</option>";

    while($row=mysqli_fetch_array($res))

    {

        echo "<option value = '$row[model_id]'>"; echo $row["model"]; echo "</option>";


    }

    echo "</select>";

}

if($model!="")

{

    $res = mysqli_query($link,"SELECT * FROM year WHERE model_id= $model");

    echo "<select id='yeardd' onchange='change_year()'>";

    echo "<option selected = '' disabled=''>";echo "Select Year";echo "</option>";

    while($row=mysqli_fetch_array($res))

    {


        echo "<option value = '$row[year_id]'>"; echo $row["year"]; echo "</option>";


    }

    echo "</select>";

}

if($year!="")

{

    $res = mysqli_query($link,"SELECT * FROM oem WHERE year_id= $year");

    echo "<select id='oemdd' onchange='change_oem()'>";

    echo "<option selected = '' disabled=''>";echo "Select OEM number";echo "</option>";

    while($row=mysqli_fetch_array($res))

    {


        echo "<option value = '$row[oem_id]'>"; echo $row["oem_number"]; echo "</option>";


    }

    echo "</select>";

}

if($oem!="")

{

    $res = mysqli_query($link,"SELECT * FROM lug_num WHERE oem_id= $oem");

    echo "<select id='lugdd' onchange='change_lug()'>";

    echo "<option selected = '' disabled=''>";echo "Select lug number";echo "</option>";

    while($row=mysqli_fetch_array($res))

    {


        echo "<option value = '$row[lug_id]'>"; echo $row["lug_number"]; echo "</option>";


    }

    echo "</select>";


}

if($lug!="")

{

    $res = mysqli_query($link,"SELECT * FROM fix_type WHERE lug_id= $lug");

    echo "<select>";

    echo "<option selected = '' disabled=''>";echo "Select fix type";echo "</option>";

    while($row=mysqli_fetch_array($res))

    {

        $test = $row["fix_name"];

        echo "<option value = '$row[fix_id]'>"; echo $row["fix_name"]; echo "</option>";


    }

    echo "</select>";

}

$img = ""


if($image!="")

{

    $res = mysqli_query($link,"SELECT * FROM lug_num WHERE lug_id= $image");

    $array = array();

    ?><br><br><div id = img_lug><?php

    while($row=mysqli_fetch_array($res))

    {


        $img = $row["image"];

        //echo $img;


        ?><img src="<?php echo $img;  ?>"  width='200' height='200' /><?php



    }

        ?></div>

<?php } ?>


索引.php


<?php

    $link=mysqli_connect("localhost","root","123456");

    mysqli_select_db($link,"demo");


?>


<!DOCTYPE html>

<html>

<head>

    <title></title>

</head>

<body>

    <form name="form1" action="" method="post">

        <table>

            <tr>

                <td>Select Make</td>

                <td><select id="makedd" onchange="change_make()">

                    <option>Select</option>

                    <?php

                        $res = mysqli_query($link,"SELECT * FROM `manufacturer`");

                        while($row=mysqli_fetch_array($res))

                        {

                            ?>


                            <option value="<?php echo $row["make_id"];?>"><?php echo $row["make"] ?></option>

                            <?php

                        }

                    ?>

                </select></td>

            </tr>

            <tr>

                <td>Select Model</td>

                <td>

                    <div id="model">

                        <select>

                            <<option selected="" disabled="">Select Manufacturer</option>

                        </select>

                    </div>

                </td>


            </tr>

            <tr>

                <td>Select Year</td>

                <td>

                    <div id="year">

                        <select>

                            <option>Select Year</option>


                        </select>

                    </div>

                </td>


            </tr>

            </tr>

            <tr>

                <td>Select OEM Number</td>

                <td>

                    <div id="oem">

                        <select>

                            <option>Select OEM Number</option>


                        </select>

                    </div>

                </td>


            </tr>                       

            <tr>

                <td>Select lug Number</td>

                <td>

                    <div id="lug">

                        <select>

                            <option>Select Lug Number</option>


                        </select>

                    </div>

                </td>


            </tr>

            <tr>

                <td>Select Fix type</td>

                <td>

                    <div id="fix" >

                        <select>

                            <option>Select Fix type</option>


                        </select>

                    </div>

                </td>


            </tr>

            <tr>

                <td>Image from lug</td>

                <td><div id="image">


                </div>

                </td>


            </tr>



        </table>

        <?php

        include "ajax.php";


        ?><img src="<?php include "ajax.php"; echo $img;  ?>"  width='200' height='200'  /><?php

        ?>


    </form>

<script type="text/javascript">

function change_make(){

    var xmlhttp=new XMLHttpRequest();

    xmlhttp.open("GET","ajax.php?make="+document.getElementById("makedd").value,false);

    xmlhttp.send(null);


    document.getElementById("model").innerHTML=xmlhttp.responseText;


}


function change_model() {

    var xmlhttp=new XMLHttpRequest();

    xmlhttp.open("GET","ajax.php?model="+document.getElementById("modeldd").value,false);

    xmlhttp.send(null);


    document.getElementById("year").innerHTML=xmlhttp.responseText;

}

function change_year() {

    var xmlhttp=new XMLHttpRequest();

    xmlhttp.open("GET","ajax.php?year="+document.getElementById("yeardd").value,false);

    xmlhttp.send(null);


    document.getElementById("oem").innerHTML=xmlhttp.responseText;

}

function change_oem() {

    var xmlhttp=new XMLHttpRequest();

    xmlhttp.open("GET","ajax.php?oem_number="+document.getElementById("oemdd").value,false);

    xmlhttp.send(null);


    document.getElementById("lug").innerHTML=xmlhttp.responseText;

}

function change_lug() {

    var xmlhttp=new XMLHttpRequest();

    xmlhttp.open("GET","ajax.php?lug_number="+document.getElementById("lugdd").value,false);

    xmlhttp.send(null);


    document.getElementById("fix").innerHTML=xmlhttp.responseText;

}



</script>

</body>

</html>



查看完整回答
反對 回復 2022-11-04
?
慕娘9325324

TA貢獻1783條經驗 獲得超4個贊

你嘗試的方式是錯誤的??矗愕?$image 變量可以是全局的,但你的循環不是全局的。它會給你循環的最后一個值。


1.將 $img 變量更改為本地變量。

2.然后創建一個新的全局變量。并給它這樣的值。


global $global_images;

$global_images.= "@".$row["image"]; // @ is just a separator.

3.現在在另一個頁面(你想要的地方),你必須再次創建基本循環,像這樣


include "2.php";


$get_images=explode('@', $global_image);  //We can choose one by one the images with @ and explode function

//The loop

foreach ($get_images as $show){?>

<img src="<?php echo $show;  ?>"  width='200' height='200'>

<?php } ?>

據我了解,這正是您想要的?,F在您可以根據需要對其進行自定義。


查看完整回答
反對 回復 2022-11-04
  • 2 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號