dongya4335 2013-04-25 16:11
浏览 36

Onclick,MySQL,PHP,关于交换图像

I’m building an SEO script and am delaying this matter for 2 weeks now without an answer. I saw dozens of answers here but none of them where satisfactory (or at least I didn’t find them useful).

I have a MySQL table with several fields, the data base has the keyword field as primary and the other fields are SEO variables for the keyword in question. OK, no problem, I put the MySQL values in the table and they are spit out into a nice table when requested by php…

I have a round button at the beginning of every row that indicates if the keyword is easy, medium or hard to optimize. Respectfully a green button, an orange button and a red button. Only one shows per row.

The color is determined by the Page Rank (a column in the table, from 0-10 (<2 – green, 2-4 orange, over 4 red)).

So my problem is simple…

I would like to click on these buttons, images or what you would like to call them and select them, they will turn blue (REPLACE THE IMAGE WITH A BLUE IMAGE) so then they can be included in the .CSV file to export.

So, I would show you the code I have but I have changed it so many times I don’t think it’s any good and not significant, but I can answer any questions.

Basically it’s changing 2 images back and forth with mysql and php on an ONCLICK basis.

It's half in Portuguese so I will translate...

$query = "SELECT `CÔR`(COLOR), `keyword`, `Adds`, `PRMédio`, `PRDomínioMédio`, `Searches`, `CPC`, `.com`, `.org`, `.net`, `All in URL`, `All in Title`, `All in Desc.` FROM keywords";

if ($query_run = mysql_query($query)) {
    while ($query_row = mysql_fetch_assoc($query_run)) {
        (COLOR)$côr = $query_row['CÔR'];
            $keyword = $query_row['keyword'];
            $Adds = $query_row['Adds'];

            $PRMédio = $query_row['PRMédio'];
            $PRDomínioMédio = $query_row['PRDomínioMédio'];
            $Searches = $query_row['Searches'];
            $CPC = $query_row['CPC'];
            $com = $query_row['.com'];
            $org = $query_row['.org'];
            $net = $query_row['.net'];
            $All_in_URL = $query_row['All in URL'];
            $All_in_Title = $query_row['All in Title'];
            $All_in_Desc = $query_row['All in Desc.'];


            echo "
            <tr>

            <th>";
            if ($PRMédio < 2) {
                echo "(GREEN BUTTON)$botao_verde";
            } else if ((2 <= $PRMédio) && ($PRMédio < 4)) {
                echo "(ORANGE BUTTON)$botao_laranja";
            } else if (4 < $PRMédio) {
                echo "(RED BUTTON)$botao_vermelho";
            }

            // this is the part where i do not know what I'm doing

            echo "<form>
                <input type='submit' name='submit' class='image'
                value=(BUTTON)'botão' onClick='UPDATE keywords SET CÔR = ~CÔR'>";
            echo "</form>
            </th>
            <td>$keyword</td>
            <td>$Adds</td>
            <td>

It continues with the rest of the columns of the table...

  • 写回答

2条回答 默认 最新

  • dongsuoying9059 2013-04-25 17:07
    关注

    This should get you started - all you need to do is generate the appropriate HTML for your rows as demonstrated below

    Javascript

    var PathToImages = "/Images/";
    
    // Let's store the initial colours in in array so we know what to toggle back to...
    var Colors = ["Red", "Blue"];
    
    // And set up somewhere to record which ones have been clicked...
    var Toggled = [];
    
    //Using jQuery this might look more elegant but I'll keep it simple
    
    function Toggle(RowNumber) { //RowNumber is 0-indexed
        var NewImageSource;
        if(Toggled.indexOf(RowNumber) < 0) {
            //Toggle on
            Toggled.push(RowNumber);
            NewImageSource = PathToImages + "Blue.png";
        } else {
            //Toggle off
            Toggled.splice(Toggled.indexOf(RowNumber), 1); //Remove the Row number from the toggled array
            NewImageSource = PathToImages + Colors[RowNumber] + ".png";
        }
        document.getElementById("Image" + RowNumber).src = NewImageSource;
    }
    

    Html

    <img src="/Images/Red.png" id="Image0" onclick="toggle(0);"/>
    <img src="/Images/Green.png" id="Image1" onclick="toggle(1);"/>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题